http://www.perlmonks.org?node_id=1013809


in reply to Going through a big file [solved]

lanX's comment at Re: Going through a big file excellently explains the difference between how for slurps the whole lot into an array, but while does it line by line. The only comment I would add is why bother to have it open the files manually when it can be done implicitly?
while (<>) { }
does the job. Arguments other than the file(s) you want to process should be flags. In fact, you don't even need to write this code as it is automatically assumed when you run perl with flags such as -n or -p. See perlrun for more information.
A Monk aims to give answers to those who have none, and to learn from those who know more.