I'm not entirely clear on what you're asking, but probably the two functions you want help with are
grep and
splice. Grep allows you to search the file for a missing line, and splice will allow you to insert it wherever you like, because the author of
Tie::File included an interface for it.
--
Love justice; desire mercy.