A good solution is to open the files with perl, using the three-argument form of
open (which correctly handles whitespaces in filenames) and use Perl regexes to search for the patterns.
You should also Use strict and warnings, and declare your variables - it catches at least two errors in your script.
Perl 6 - links to (nearly) everything that is Perl 6.