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