in reply to Re^2: substitution in regular expression
in thread substitution in regular expression

Maybe (?) something like this is what you want?

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'ABCDEF'; ;; my @triplets; $s =~ s{ (?= (...)) . }{ push @triplets, $1; ''; }xmsge; ;; print qq{'$s'}; printf qq{'$_' } for @triplets; " 'EF' 'ABC' 'BCD' 'CDE' 'DEF'

Update: Here's another  s/// solution. I'm not sure I like it so much: I'm always suspicious, perhaps without cause, of code embedded in a regex. In addition, the  @triplets array must be a package global (ideally local-ized) due to a bug in lexical management that wasn't fixed until Perl version 5.16 or 5.18 (I think — I don't have access to these versions and I'm too lazy to check the on-line docs).

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'ABCDEF'; ;; local our @triplets; $s =~ s{ (?= (...) (?{ push @triplets, $^N })) . }''xmsg; ;; print qq{'$s'}; printf qq{'$_' } for @triplets; " 'EF' 'ABC' 'BCD' 'CDE' 'DEF'