@tokens = split /(\s+)/, $text, -1; # keep all white-space my $trunc_str = ''; for ( @tokens ) { $trunc_str .= $_; last if ( /\S/ and --$last_word == 0 ); } return $trunc_str; }