Not for the low level problem of inserting lines in a file, but for the general purpose of managing a configuration file, you might also consider using a dedicated module.
A quick search on CPAN leads for example on those ones :
Parse::PlainConfig may be the most interesting in this case, as it allows both to write the configuration file and to store lists (were they of servers or of something else) and even hashes.
In reply to Managing config files
by linkeditor
in thread Inserting lines in a file with Tie::File if lines don't exist
by devgoddess
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |