my $string_three = 'foo bar [21a] plus (b23) baz bax'; my @string_three_results = $string_three =~ m{ (\d+) (a|b) | (a|b) (\d+) }gx; print "RESULTS: " , Dumper(\@string_three_results), $/; # RESULTS: $VAR1 = ['21','a',undef,undef,undef,undef,'b','23'];