i'd actually use a different tack and that is, use Tie::File module, letting the module take care of the correct file reading/writing...you just maintain a 5 element array or hash, depending on which (hash or array) is most suitable.
the hardest line to type correctly is: stty erase ^H