If your test.txt file is long, it may make sense to pre-compile the entries for faster searching. Also, you want to make sure to use
\Q and
\E to make sure wildcards in the file names don't get expanded.
Also, please check return codes on system calls such as
open().
Consider something like the following:
my @patterns;
foreach my $pattern (`ls`) {
chomp $pattern;
push @patterns, qr/\Q$pattern\E/;
}
open(IN,"test.txt") or die "Can't open test.txt: $!\n";
while(my $line = <IN>) {
chomp $line;
foreach my $pattern (@patterns) {
print "Match found\n" if $line =~ $pattern;
}
}