in reply to While.For loop noob query

Using eof is the right approach... What was your eof attempt? Looking at your code above, you can't count the lines like that without reseting the file before reading the whole thing again.. I believe that this should work (untested):
open(TXTIN,"ARGV[0]") || die "Cannot open the data file"; open(TXTOUT,">ARGV[1]") || die "Cannot open the formatted file"; while(<TXTIN>){ # gets a line from input file if( eof TXTIN ){ # eof returns true if the _next_ re +ad would fail, meaning s/different/regex here/; # the one we just read was the l +ast line }else{ s/yada/yadda/; } print TXTOUT $_; } close(TXTIN); close(TXTOUT);
Also, i don't think you want to chomp the input and then not write a newline to the output file (so i just omitted the chomp from my snippet)...

Note that (and this one i tested) you can also use the commandline here:
perl -pe 'if( !eof ){ s/^1/AAAA/; } else{ s/^1/BBBB/; }' /etc/hosts > +/tmp/newfile
And if you want to do an in-place edit (see perlrun) you can just add the -i command-line parameter.

one last note: if you're not doing use strict; and use warnings;, they will be invaluable to you to add.. (maybe you just omitted them from your code snippet -- just worth double-checking)

ok, one last note-- it doesn't apply to this specific task, but the $. variable might be of interest to you -- see perlvar (e.g. if you wanted the first line to have a different regex)