in reply to using unlink to delete files

I think you what to do this:

for my $f (@files) { if (-z "$maid_dir/$f") { unlink("$maid_dir/$f"); } }

Note that the -z file test returns true for zero-size files, and readdir gives you filename, but not the full path.