last night I went to the philly pm to hear Mark Dominus talk about Tie::File. Tie::File is a pretty cool interface for tie()'ing a file to an array, which you can then push(), pop(), shift(), and otherwise manipulate in order to make changes to the underlying file.
the changes are made in real time, with the benefit of a heuristic performance inhancment. so, if you are manipulating lines (the values in the array) at random the changes are made immediately, but if you are working on sections of the file they are buffered for performance.
Tie::File has been integrated into core for 5.8, but you can get it from CPAN now if you want to play around with it.