sub trim_length { my($string, $desired_length) = @_; # edit: swiped idea from Tachyon if((length($string)) < $desired_length) { return $string; } my @words = split(" ", $string); my $clipped = ""; foreach(@words) { my $temp = $clipped; $clipped .= $_; if((length($clipped)) > $desired_length) { $clipped = $temp; last; } } if((length($clipped)) == 0) { $clipped = substr($string, 0, $desired_length); } $clipped .= "..."; return $clipped }