open( my $fh => '+<', $your_file ) or die "ack: $!"; ## read up to a point read_stuff() or last while <$fh>; ## remember where you were my $last_pos = tell $fh; my $rest_of_file = do { local $/; <$fh> }; $rest_of_file =~ s<$a_regex>($replace); ## go back to where you were seek $fh => $last_pos, 0; print {$fh} $rest_of_file; close $fh;