local our @matches; $str =~ / (?{ [] }) ^foo (?: \s+ m \s+ (\d+) (?{ [ @{$^R}, $^N ] }) )+ \s+ bar (?{ @matches = @{$^R} }) /x;