>perl -wMstrict -le "my $s = 'ABC1D A2D'; my @matches = $s =~ /A(?:BC|)(.*?)D/g; print qq{'$_'} for @matches; " '1' '2'