use v5.14; use re "/sixm"; $_ = "This part is past all of this paaRTy of the string. Paaaaarty on!"; my @matches = (); sub show_matches { printf "Got %d matches:\n", scalar @matches; my $i = 1; for (@matches) { printf " %2d\t$_\n", $i++, $_; } } @matches = / pa .* rt /g; show_matches(); @matches = / pa .*? rt /g; show_matches(); @matches = / (?= (pa .* rt) ) /g; show_matches(); @matches = (); () = / (pa .* rt) (?{push @matches, $^N}) (*FAIL) /g; show_matches(); #### Got 1 matches: 1 part is past all of this paaRTy of the string. Paaaaart Got 3 matches: 1 part 2 past all of this paaRT 3 Paaaaart Got 4 matches: 1 part is past all of this paaRTy of the string. Paaaaart 2 past all of this paaRTy of the string. Paaaaart 3 paaRTy of the string. Paaaaart 4 Paaaaart Got 8 matches: 1 part is past all of this paaRTy of the string. Paaaaart 2 part is past all of this paaRT 3 part 4 past all of this paaRTy of the string. Paaaaart 5 past all of this paaRT 6 paaRTy of the string. Paaaaart 7 paaRT 8 Paaaaart