http://www.perlmonks.org?node_id=375519


in reply to In search of a better way to trim string

Alternative with regex:
sub trimTo { my ($line, $length) = @_; $line =~ s/^(.{0,$length}\s|.{$length}).*/$1.../; return $line; }
I think has the same behaviour as the others. Not tested fully. Not that I think it's any faster than any substr method, but it's an alternative.