substr $_, $offset, 0, $added_text; # or substr( $_, $offset, 0) = <## s/$pattern/$new_text/sg;