in reply to Which one is best for optimization

When you say "Delete the file", do you mean actually delete a file, or delete the file from your hash? If the former, use unlink, not delete.

In Perl, "break" is called last. But it doesn't seem like you'd want to break out of your foreach loop.