$string =~ m{ (?{ [ pos ] }) # we start $^R as [ pos ] ([a-z]{3}) # find a string, store it in \1 (?: # now do this one or more times: .*? # match zero or more characters (non-greedily) (?{ [ @{$^R}, pos ] }) # append pos() to $^R's arrayref \1 # matching \1 at this location )+ (?{ @loc = @{$^R} }) # then save $^R }x