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


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

Hm, there's Text::Truncate:

use Text::Truncate; my $short = truncstr($long, $len);

It may not be the most efficient way to do it, but you don't have to think about how to do it.

Disclaimer: I wrote that module a while ago because I was sick of rewriting a routine to do that all the time. Any ideas for improvements would be appreciated.