in reply to Match only certain characters?

One way to do it, (using tr).

#!/usr/bin/perl use strict; use warnings; my $s='ABCAAAABBBCCCCCAAABBBCCC'; if (0 == $s =~ tr/ABC//c) { print "All letters are A B or C"; }
Note that I didn't use $a or $b as those should be reserved for the sort function.

Chris