use strict; use warnings; my $t = "Call me a joker call me a fool. Right at this moment Im totally cool. Clear as a crystal, sharp as a knife. I feel like Im in the prime of my life. Sometimes it feels like I'm going to fast. I dont know how long this feeling will last. Maybe its only tomihgt."; my ($string, $i); my $s = length $t; if ($s > 39){ my $i = 39; while ($i < $s){ if ($i == 39){ $i = index($t," ", $i); $string = substr($t, 0, $i); print $string; } else{ my $i2 = index($t, " ", $i+60); if ($i2 == -1){ my $end = substr($t, $i, $s); $end =~s/^\s+//; $string .= "\n" . $end; last; } else{ print $i . " " . $i2 . "\n"; my $end = substr($t, $i, $i2-$i); $end =~s/^\s+//; $string .= "\n" . $end; $i = $i2; } } } } print $string;