in reply to adding lines at specific addresses

Tie::File will be a big help - it will let you treat the file as an array of lines. You'll be able to splice in a line while examining the surrounding context, and the modifications will appear on disk. You simply address the lines with an array index.

After Compline,
Zaxo