sub trunc { my ( $last_word, $text ) = @_; return '' unless ( $last_word =~ /^\d+$/ and $text =~ /\S/ ); @tokens = split /\s+/, $text; return join " ", @tokens[0..$last_word-1]; }