in reply to Arbitrary number of captures in a regular expression

It is possible to do with one regexp.

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

Didn't say it was nice.