#!/usr/bin/perl -w "abcde" =~ /(..)(?:(....)|(..))/; # $1 is 'ab' # $2 is undef # $3 is 'cd' print length($2); #### #!/usr/bin/perl -w print length($foo); #### /* n is the number in $N */ if ( (n <= rx->nparens) && (s = rx->startp[n]) != -1 && /* -1 => not there */ (e = rx->endp[n]) != -1 ) return e - s; return 0;