in reply to Code Error Question

It should very likely be:
unlink($file) or die $!;
In other words, unlink ("delete") the file specified in $file or die giving the system's error message.

If you want to have a clearer error message, use:

unlink($file) or die "Can't unlink '$file': $!";
update: I have no idea what the /$size/ match is supposed to do, but it's probably wrong. Also, having a variable named $file and another named $filename in a related code block is suspicious - especially if you're not using strict and warnings.