Provided that your file isn't too huge, you'd probably be better off (easier) using Tie::File.
In reply to Re: Change a line in a file by BrowserUk in thread Change a line in a file by rightfield