I find that the absolute easiest way to handle file editing (if the file's not too big) is to use Tie::File. This lets you treat the file as if it were an array; if you case you could then just splice in the items you want.
Comment on Re: what is the best method to read and write in a file in perl