in reply to count consecutive characters

Untested:
while ($str =~ /(N+)/g) { print length($1), "\n"; }

See perlretut and maybe perlre for an explanation.

(Updated after reading the question more carefully this time)