use strict; use warnings; my $dir = '/etc'; while (1) { print "Enter pattern> "; chomp( my $pattern = ); ## I'm talking about this line last unless defined $pattern and length $pattern; my @matched = eval { grep { /$pattern/ } glob "$dir/*"; }; print "Error: $@" if $@; print map { "$_\n" } @matched; }