The only tricky part is that you need to stash away at least the part of File A after *** Initial Temperature somewhere so when you write file B there you don't lose it. The easiest code to do this is just to read all of file A into memory. If it is too big, you would rename the file and create a new file A instead. Alternatively, modules like Tie::File can hide some of the details from you.