#sub captures { # local $_ = shift; # croak "$_ is not a compiled regexp" unless ref eq 'Regexp'; # my $n = 0; # while( /\G(?=.)/gcs ) { # /\G[^\\(]*/gc; # ignore uninteresting stuff # /\G(?:\\.)*/gc; # ignore backslashed stuff # /\G\(\?/gc; # ignore special regexps # /\G\(/gc && $n++; # a capturing (, count it! # } # $n; #} sub captures { ( @_ = '' =~ /(@{[shift]})??/ ) - 1; }