>perl -wMstrict -le "my $s = 'Fu Feet Fie Foe Fum'; my $f = qr{ F \w* }xms; for my $rx ( qr{ (X) }xms, qr{ ($f) \s* ($f) }xms, qr{ ($f) \s* ($f) \s* ($f) }xms, qr{ ($f) \s* ($f) \s* ($f) \s* ($f) }xms, ) { $s =~ $rx; print qq{highest capture group is $#-, captures are}; printf qq{\$$_->[0] eq '$_->[1]' } for map [ $_, eval qq{\$$_} ], 1 .. $#-; print qq{\n}; } " highest capture group is -1, captures are highest capture group is 2, captures are $1 eq 'Fu' $2 eq 'Feet' highest capture group is 3, captures are $1 eq 'Fu' $2 eq 'Feet' $3 eq 'Fie' highest capture group is 4, captures are $1 eq 'Fu' $2 eq 'Feet' $3 eq 'Fie' $4 eq 'Foe'