use warnings; use strict; foreach my $str ( 'LLLLLLLLLLLLLLLLLLLOOOOOOOOOOOOO', 'LLLLLLLLLLCOOOOOOOOOOOOOOOOOOOOOO' ){ if($str=~/^(L+)/ or $str=~/^(L+C)/) { print "matched '$1'\n"; } } __END__ matched 'LLLLLLLLLLLLLLLLLLL' matched 'LLLLLLLLLL'