my @ss = qw( A B C AB CA ABC xABCx BxCxAx ); for (@ss) { if (/A/ && /B/ && /C/ && !/[^ABC]/) { print "$_\n"; } }