in reply to Why -M doesn't work?

You're reading file names from a directory and storing them in an array. If you want to operate on those file names, you need to include your file path with the file name in the operation.
#!/usr/bin/perl my $dir = "D:\\Log\\tmp"; if(opendir LOGS, "$dir"){ my @myfile = grep( /^*.tmp$/, readdir (LOGS)); foreach $file(@myfile){ my $result=-M "$dir\\$file"; if( $result> 7){ unlink ("$dir\\$file"); } } } closedir LOGS;