#!/usr/bin/perl -w use strict; my @strings = ('ABCAAAABBBCCCCCAAABBBCCC', 'ASRGRTGRT89579843rrrrrr', 'A98797BqrtoiquyrtoCafdgagfd'); foreach (@strings) { # Here the scalar count value of tr is used # tr is very fast but lacks the flexibility of # regex # prints the string unless it has some char that is # not an A, B, C. print "$_\n" if !(tr/ABC//c); } # Prints: ABCAAAABBBCCCCCAAABBBCCC #### my $standard='ABCAAAABBBCCCCCAAABBBCCC'; my %seen; my @unique_letters = grep{$seen{$_}++ <1 } split(//,$standard); my $unique_letters = join("",@unique_letters); # these above two lines could be combined, but I think it # reads better this way, and YES, it is completely legal in Perl # to have an array variable named unique_letters and a # string named the same thing. Update: with same name not same "thing". foreach (@strings) { print "$_\n" if (/[^$unique_letters]/); } #prints: #ASRGRTGRT89579843rrrrrr #A98797BqrtoiquyrtoCafdgagfd #change to "not" of these: (!/[^$unique_letters]/); #to get: ABCAAAABBBCCCCCAAABBBCCC