sub chop_to_size { my ($text, $length) = @_; return $text if length $text < $length; # make room for ellipsis my $chop = $length - 3; $text =~ s/^\s*(.{$chop})\s*.+$/$1/; $text =~ s/[\s[:punct:]]+$//; $text .= "..."; $text; }