my $new = ''; for (;;) { # or: for ($orig) if (/\G(.*?)(this)/sgc) { say "Matched $2 at $-[2]"; $new .= $1 . 'that'; redo; } else { /\G(.*)/sgc; $new .= substr($_, pos); last; } }