in reply to clobbering output

if (/^#!/) {
would be more accurate as
if ($. == 1 && /^#!/) {

Replies are listed 'Best First'.
Re^2: clobbering output
by Anonymous Monk on Feb 25, 2008 at 06:47 UTC
    You suggest the use of $., but perlvar cautions with respect to $. that

    Because ``<>'' never does an explicit close, line numbers increase across ARGV files (but see examples under eof()).

    The OP seems to want to process multiple files from the command line. The relevant example from the entry for eof is:

    # reset line numbering on each input file while (<>) { next if /^\s*#/; # skip comments print "$.\t$_"; } continue { close ARGV if eof; # Not eof()! }