in reply to PCRE: Repeating Subpattens After Intervening Characters

Taking advantage of specific features of your regexp,

@matches = map { /^(\d\s+foo)/; $1 } /(?:\d\s+foo[^\r\n]*)/g;

This will validate and return matches. If you just wish to validate, the following will suffice:

# Specific case: /(?:\d\s+foo[^\r\n]*)/; # General case: $repeated = qr/\d\s+foo/; /(?:$repeated[^\r\n]*)$repeated/;

Update: My capture version has two issues. And the pattern is still repeated.

You really do want a parser for this:

list : term list_ { [ $item[0], $item[1], @{$item[2]} ] } list_ : sep term { [ $item[1], @{$item[2]} ] } | { [ ] }