use 5.010; # re features use strict; use warnings; for ('abcdef') { m{ (?(DEFINE) (? ( . ) ( . ) (?{ '...' }) ) (? ( . ) ( . ) (?{ print("(???,$^N)") }) ) (? ( . ) ( . ) (?{ '...' }) ) ) (?&y)+ }x; } print("\n"); #### use 5.010; # re features use strict; use warnings; sub CAP { my ($idx) = $_[0]; $idx += @- if $idx < 0; # @+ isn't the same size as @- substr($_, $-[$idx], $+[$idx] - $-[$idx]) } for ('abcdef') { m{ (?(DEFINE) (? ( . ) ( . ) (?{ '...' }) ) (? ( . ) ( . ) # (?{ # printf('[%s,%s]', # ($#-), # Prints 6, the number of preceding captures # ($#+), # Prints 9, the total number of captures # ) # }) (?{ printf('(%s,%s)', CAP(-2), CAP(-1) ); }) ) (? ( . ) ( . ) (?{ '...' }) ) ) (?&y)+ }x; } print("\n");