http://www.perlmonks.org?node_id=544756


in reply to Delimited Backtracking with Regex

Take advantage of regexp backtracking to find all the possibilities.

my $str = "TXXXABCDGXXXCCCDTGYYYCCCYYYCC"; local our @matches; $str =~ m/ (XXX.*YYY) # Search and capture (?{ push @matches, $1 }) # Save result (?!) # Try again /x; print "$_\n" foreach @matches;

outputs

XXXABCDGXXXCCCDTGYYYCCCYYY XXXABCDGXXXCCCDTGYYY XXXCCCDTGYYYCCCYYY XXXCCCDTGYYY

Update: Followed japhy's suggestion