in reply to Match only certain characters?

How about a positive look ahead assertion?, since you only wanted to pick the string that contained the pattern provided, you don't have to capture the match and instead it would only be sufficient if you lookedaround for its existence. Reading the documentation for Regexes to walk you through can be a good idea ..
#!/usr/local/bin/perl use strict; use warnings; #f = first, s = second. my $f='ABCAAAABBBCCCCCAAABBBCCC'; my $s='ASRGRTGRT89579843rrrrrr'; print $f=~/(?=^[ABC]+$)/? "Matches [ABC] Combinations\n": "No pattern +found!\n"; print $s=~/(?=^[ABC]+$)/? "Matches [ABC] Combinations\n": "No pattern +found!\n";
#OUTPUT: Matches [ABC] Combinations No pattern found
Update: added a link that might benefit the OP.


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.