use strict; my $a='ABCAAAABBBCCCCCAAABBBCCC'; my $b='ASRGRTGRT89579843rrrrrr'; print '$a matches',$/ if $a =~ /^[ABC]+$/; print '$b matches',$/ if $b =~ /^[ABC]+$/;