>perl -wMstrict -le "my $gotA = qr{ (?= .*? A) }xms; my $gotB = qr{ (?= .*? B) }xms; my $gotC = qr{ (?= .*? C) }xms; my $onlyABC = qr{ (?! .*? [^ABC]) }xms; for my $s (@ARGV) { my $match = $s =~ m{ \A $gotA $gotB $gotC $onlyABC }xms; print qq{'$s' }, $match ? 'matches' : 'no match'; } " "" A B C AB AC BC ABC CAB ABABCBCBCACA xABC ABCx xA xB xC Ax '' no match 'A' no match 'B' no match 'C' no match 'AB' no match 'AC' no match 'BC' no match 'ABC' matches 'CAB' matches 'ABABCBCBCACA' matches 'xABC' no match 'ABCx' no match 'xA' no match 'xB' no match 'xC' no match 'Ax' no match