Maybe you have a typo in the while, you are using input instead of input1
while($query->param('input')) {
You could add something to $reply to see it is displayed at all:
You should use foreach instead of while and you could use grep:
my $from_sara;
foreach my $input ($query->param('input1')){
foreach my $pattern (grep {/^\s*$input\s*$/is} keys %words){
@answers = @{$words{$pattern}};
$from_sara = $answers[int rand($#answers + 1)];
last;
}
last if $from_sara;
}
my $reply = "Answer from Sara:\n$from_sara\n";