c:\@Work\Perl\monks>perl -e "use warnings; use strict; use feature qw{ say }; ;; for my $string (qw(ab1b2b3b4d ab5b6b7d ab8b9d abxd ad)) { my @two; my @matches = $string =~ /(a) (b.(?{ push @two, $2 if defined $2 }))+ (d)/x; say for @matches, '---', @two, '======'; } " a b4 d --- b1 b2 b3 ====== a b7 d --- ====== a b9 d --- ====== a bx d --- ====== --- ======