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


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

This assumes there are no newlines in the original string (at least not in an inconvenient place):
use Text::Wrap qw(wrap $columns); $columns = 30; my $trimmed = wrap('', '', $str); $trimmed =~ s/\n.*/.../s;