use strict; use warnings; my $len = 40; print "0123456789012345678901234567890123456789\n"; while ( my $string = ) { chomp $string; $string =~ s/((?:.{0,$len}(?=\s|$))|(?:\S{$len}))(?:.+$)?/$1.../s; print "$string\n"; } __DATA__ Now is the time for all good men to come to the aid of their country. Nowisthetimeforallgoodmentocometotheaidoftheircountry.