$ echo 'heaven > heavenly > heavenns > abc > heavenns > heavennly' | perl -nE 'BEGIN {$nr = shift;} chomp; say length $_ if $. == $nr;' 4 3