in reply to modifying and overwriting a file

I like to take advantage of perl's command-line switches, so I'd do something like this:
#!perl -pli $_ .= '_' unless $. == 1; # append underscore, except on first line close ARGV if eof; # reset line numbering at end of file
-p loops over the input, reading it into $_ and printing it back out. -l handles line-endings. -i modifies files in place.