# 1 2 3 # 123456789012345678901234567890 my $str_type1 = "ccaatTTTGACACACACAGAAgggca"; # no dash my $str_type2 = "--aatTTTGACACACACAGAAgggca"; # with dash for ( $str_type1, $str_type2 ) { if ( m{^(-*)[^A-Z]*([A-Z]*)} ) { my ( $s, $e ) = ( $-[2] + 1, $+[2] ); $_ -= length $1 for $s, $e; print "$_\n"; print "From = $s to $e\n\n"; } } #output: ccaatTTTGACACACACAGAAgggca From = 6 to 21 --aatTTTGACACACACAGAAgggca From = 4 to 19