http://www.perlmonks.org?node_id=349904


in reply to Trying to count the captures in a compiled regular expression

How about just using it, marked optional, and seeing how many captures you get?
$_ = 'anything'; my @capture_count; my $regex = qr/one(.*?)((two)(four))/; @capture_count = /(?:$regex)?/; print @capture_count." captures\n";

The PerlMonk tr/// Advocate