use strict; use warnings; my $input_file='file.txt'; while (1){ # Infinite loop print "Enter the word you are looking for (or 'quit' to exit): "; my $answer = ; chomp $answer; # remove newline char from answer last if $answer =~/quit/i; # Exit loop print "Looking for '$answer'\n"; my $found = 0; open my $f, "<", $input_file or die "ERROR: Cannot open $input_file : $!"; while (<$f>) { m/$answer/ or next; $found=1; last; } close $f; if ($found){ print "Found $answer!\n"; }else{ print "Sorry - $answer was not found\n"; } }