Let's summarize the problems:
- You're not checking the return value of opendir, so you don't know if it succeeded.
- You're not checking the return value of open, so you don't know if it succeeded.
- You should be opening the '/mail' directory, not "mail" (which is what the string looks like after the backslash is processed away).
- You are attempting to read from '$file' (that's the literal filename $file), when you mean to be reading from the filename contained in the scalar variable $file.
- You're calling your input filehandle WRITE, which isn't a bug but is confusing.
Fix those things and see how it goes.
Update: At Not_A_Number's request/suggestion I'm updating to add the very good points mentioned by MidLifeXis and toolic.
- The file you open needs to have the path prepended to it.
- readdir returns the '.' and '..' directories too. A -f test would determine that you're looking at a file, not another directory.
- autodie would eliminate the need to explicitly check the return values of your IO operations.
That gives you a total of eight "bullet points" to work on. Once they're resolved, assuming some other problem hasn't been introduced in the process, you'll be on track.