opendir(my $dh, '.') or die("Unable to list directory: $!\n"); my %searchlist = map { $_ => 1 } grep { /^\.\.?$/ } readdir($dh); open(my $fh_in, 'test.txt') or die("Unable to open input file test.txt: $!\n"); while (my $line = <$fh_in>) { chomp $line; print("Match found\n") if $searchlist{$line}; }