use strict; use warnings; my @files = ( 'file1.txt', 'a.exe', 'my.log'); my @files2 = ; foreach(@files){ my $regex=$_; $regex =~ s/\./\\\./; # replace the '.' in file.ext # with '\.' so it will work in the match. print "\n\tuse $regex as the regex\n"; foreach my $file2(@files2){ chomp $file2; print "---", $file2, "\n"; if ($file2 =~ /$regex/i){ print "\tmatched with //i...\n"; if ($file2 ne $_){ print "\tbut not with string compare.\n"; } else {print "\tand with string compare.\n";} } } } #this one was missing __DATA__ File1.txt A.exe B.ext my.log