sub wrap { my $txt = $_[0]; my $wrap_at = 60; my @w_lines = (); my $l_wrapat; if(length($txt) > $wrap_at) { for(my $i = 0; $i < length($txt);$i+=$l_wrapat) { $l_wrapat = $wrap_at; if (substr($txt, $i, $l_wrapat) =~ /\s/) { while ($i+$l_wrapat < length($txt) and substr($txt, $i+$l_wrapat, 1) !~ /\s/) { $l_wrapat-- } } my $nline = substr($txt, $i, $l_wrapat); $nline =~ s/^\s*//g; push(@w_lines, $nline); } } $txt = join("\n", @w_lines); }