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


in reply to Re: Re: Trying to count the captures in a compiled regular expression
in thread Trying to count the captures in a compiled regular expression

Security alert: that will run code in (??{ }) / (?p{ }). Maybe something like this instead?
$regex = qr:(??{print "look ma, no rm -rf /\n"}):; $captures = (() = ""=~/(|$regex)/) - 1;
Also, note that you have to add a () set and then subtract it from the count to be able to distinguish between 0 captures and 1 capture.