use 5.016;
use autodie;
my $file_name = 'sample.txt';
open my $fh ,'<',$file_name;
chomp (my @strings=<$fh>);
while(1) {
say 'Please enter a pattern:';
chomp(my $pattern =<STDIN>) ;
last if $pattern =~ /\A\s*\Z/;
my @matches = eval {grep /$pattern/,@strings};
if($@) {
print "Error: $@";
} else {
my $count = @matches;
say "There where $count matching strings:",
map "$_\n", @matches;;