$num = $s =~ tr/\n// counts the newlines and is pretty cheap...
In reply to Re: Char counting by Eliya in thread Char counting by dd-b