my $string = '---LL--C----LCSH-------CSHL-------LCSLH-------LCCHLSHCL----'; while ($string =~ /[CSH][CSHL]+/g) { print "$&, "; }