>perl -wMstrict -MData::Dump -le "my $s = 'AAA BBB CCC DDD AAA BBB'; ;; my @captures = $s =~ m{ (AAA) | (BBB) | (XXX) | (YYY) }xmsg; dd \@captures ;; my @matches = grep defined, $s =~ m{ (AAA) | (BBB) | (XXX) | (YYY) }xmsg; dd \@matches; " [ "AAA", undef, undef, undef, undef, "BBB", undef, undef, "AAA", undef, undef, undef, undef, "BBB", undef, undef, ] ["AAA", "BBB", "AAA", "BBB"]