in reply to file's treatment

Advice not related to your question.

Glancing at your code, you are clearly not using strict.pm. It is generally a good idea to use that, and then declare all of your variables with my or use vars.

The biggest single win that you'll get is that for a small amount of extra declarations, you will catch many typos because Perl will notice that variables are undeclared. (Much better than just having your program silently misbehave for difficult to track down reasons.)