in reply to
Perl Pattern Matching & RegEx's
The main problem is matches in /g cannot overlap. This can be solved by using look-ahead, though:
#!/usr/bin/perl
use warnings;
use strict;
use feature qw(say);
my $string = 'AAAbcdAAAdcbAAAbbdAAAxAAAA';
my $delimiter = 'AAA';
my @positions;
push @positions, pos($string) while $string =~ /(?=$delimiter)/g;
for my $from (@positions) {
for my $to (grep $_ - length $delimiter > $from, @positions) {
say substr($string, $from, $to - $from) . $delimiter;
}
}
Update: Typo fixed. Thanks jaiieq, damn netbooks.