$str = "of course, japhy thought of this one"; $parts = 3; # ooh, not 2! $len = int(length($str)/$parts); while (--$parts and $str =~ s{( ?)([^ ]*)(?<=^.{$len})([^ ]*)( ?)} { length($2) < length($3) ? "\n$2$3$4" : "$1$2$3\n" }e ) { push @parts, ($str =~ s/(.*\n?)// and $1); } $str = join("", @parts) . $str; print $str; __END__ of course, japhy thought of this one
|
|---|