sub wordBreak { my ($string) = @_; my $tmp = ""; my @result = (); my @array = (); # # break the input into "lines" # @array = split(/^/m, $string); # # turn on swallow ending white space mode and # chomp the array elements # $tmp = $/; $/ = ""; chomp(@array) if ($#array >= 0); $/ = $tmp; @result = split( ' ', # split the one line into words join( ' ', # join the "lines" into one map { s/\s+/ /g; # get rid of extra whitespace s/^ //; s/ $//; } @array ) ) if ($#array >= 0); return @result; }