my $string = '123perl456perl789perl10'; while ($string =~ /(?<=(..))perl(?=(..))/g) { print "$1perl$2\n"; }