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


in reply to How to process multiple input files?

Try using the while construct with the <> operator. Something like

while (my $line = <>) { ... }

Oops, after submission I saw jwkrahn responded in more detail. That comment should solve (both) your problems, which I now understand to be 1) looping over command line file names, and 2) Modifying the second line of each file. One thing you might do instead of maintaining your own counter would be to use the built-in line counter. The special $. line number variable will be properly maintained from file to file. (will not be properly maintained with the <> operator unless you take special steps as described in the link given. Thank you again jwkrahn.)