in reply to
pattern matching compilation errors
Without wanting to repeat what others said before me, there's one part in this line that stood out to me.
open(FILE,"<",$filename1) or die "\n...Cannot find the file: $filename
Namely, the error message. "Cannot find the file" might not be the best to put there. There could be all sorts of other reasons the file couldn't be opened. Perhaps the process doesn't have the right permissions, maybe the file is locked, maybe there are tons of other things that could go wrong. But that's okay, because you can make Perl tell you (more or less) exactly what went wrong!
... or die "\n... Can't open $filename: $!\n";