Just a few comments to put you on track:
- start your script with #!/usr/bin/perl -w (or your path)
- always use strict at the beginning of your program, in this way you'll see you need my $debug and my in front of $mask and $file as well
- spell filehandles in CAPITAL LETTERS, it's not just a convention, future reserved words may clash with your filehandles otherwise
- since you're using open, there's no need for backticks inside double quotes. Better yet, get rid of that nasty open using glob in your while loop. Not only this improves your script's security, but it doesn't need to call an external program anymore
I hope this helps!
-- TMTOWTDI