in reply to Replace current line in while loop

In addition to both of tilly's excellent pieces of advice, you could consider the $^I variable (which you can read about in perlvar). You could also consider something like Tie::File.

Tie::File would be a better way than messing with $^I within a multi-line program if only for sake of maintainability.

Really, though, a database is made to update data in place, so that work is already done. You could use a simple key/pair database or a full-blown relational DB like PostgreSQL.