use strict; use warnings; my $str='ABC---DR----EEEEEGGGG-GRE-RED----KKKK---'; my $len_seq = () = $str =~ /[^-]/g; #### perldoc -q count