in reply to Write code using less lines

Yes, you can do it in one line (instead of three). The following counts all non-dash characters, without modifying your original string :
use strict; use warnings; my $str='ABC---DR----EEEEEGGGG-GRE-RED----KKKK---'; my $len_seq = () = $str =~ /[^-]/g;

This is a FAQ:

perldoc -q count

See also:

Replies are listed 'Best First'.
Re^2: Write code using less lines
by AR (Friar) on Apr 19, 2010 at 17:11 UTC

    In addition, you could do:

    my $len_seq = $str =~ tr/A-Za-z//;

      Or possibly:

      my $len_seq = $str =~ tr/-//c;