http://www.perlmonks.org?node_id=1037393


in reply to text to array

This is almost a duplicate of an earlier question (Modifying text file). There are plenty of answers there. You can respond or amend the question without creating a new one.
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)