c:\@Work\Perl\monks>perl -wMstrict -le "my $string = 'ab1b2b3b4d'; my @two; my @matches = $string =~ /(a) (?: (b.) (?{ push @two, $2 if defined $2 }))+ (d)/x; print qq{'$string' -> all:(@matches) -> 2:(@two)}; ;; $string = 'ab5b6b7d'; @two = (); @matches = $string =~ /(a) (?: (b.) (?{ push @two, $2 if defined $2 }))+ (d)/x; print qq{'$string' -> all:(@matches) -> 2:(@two)}; ;; $string = 'ab8b9d'; @two = (); @matches = $string =~ /(a) (?: (b.) (?{ push @two, $2 if defined $2 }))+ (d)/x; print qq{'$string' -> all:(@matches) -> 2:(@two)}; ;; $string = 'abxd'; @two = (); @matches = $string =~ /(a) (?: (b.) (?{ push @two, $2 if defined $2 }))+ (d)/x; print qq{'$string' -> all:(@matches) -> 2:(@two)}; ;; $string = 'ad'; @two = (); @matches = $string =~ /(a) (?: (b.) (?{ push @two, $2 if defined $2 }))+ (d)/x; print qq{'$string' -> all:(@matches) -> 2:(@two)}; " 'ab1b2b3b4d' -> all:(a b4 d) -> 2:(b1 b2 b3 b4) 'ab5b6b7d' -> all:(a b7 d) -> 2:(b5 b6 b7) 'ab8b9d' -> all:(a b9 d) -> 2:(b8 b9) 'abxd' -> all:(a bx d) -> 2:(bx) 'ad' -> all:() -> 2:()