If you don't have time to read this, just use

open my $fh, '+<', $filename or die;

If you have time, read on.

In most cases when you need to updated a file the best strategy is to read the entire file into memory, make the changes and then write the whole file back. Well, of course unless the file is too big, which is a separate story.