my $content; open FILE, '+<', 'file.dat' or die "Could not open 'file.dat': $!\n"; $content = $_ for (); $content =~ s/(?<=^"\w)(\d{6})/sprintf "%06d", $1 + 1/e; print FILE "\n$content"; close FILE;