perl -nwE 'say for m/(.{0,75} )/g' textsample2.txt
HAMLET: To be, or not to be--that is the question: Whether 'tis nobler in
the mind to suffer The slings and arrows of outrageous fortune Or to take
...
Работает как шарм. Если в вашем тексте нет очень длинных слов, просто подправьте цифры.
Конечно, сначала вам придется удалить все старые разрывы строк. Итак, что-то вроде:
sub wrap_text {
my ($text, $len) = @_;
$text =~ s/[\r\n]+//g; # yeah, removing \r while at it
return ( $text =~ m/(.{0,$len} )/g );
}
А потом:
say for wrap_text($text, 300);