sub wrap { my $width = shift; my @msgs; foreach my $in (@_) { my $realline = ""; my $line = ""; # Leading whitespace SHOULD be preserved!!! my $lead; if ($in =~ s/^(\s+)//) { $realline .= $1; $line .= $1; $lead = 1; } else { $lead = 0; } # My homegrown word wrap that disregards tags! foreach my $realword (split(/\s/, $in)) { # Strip the word first. my $word = $realword; $word =~ s/<[^>]+>//g; if (length($line) + length($word) + 1 <= $width) { $word = " $word" unless length($line) == 0 or $lead; $realword = " $realword" unless length($realline) == 0 or $lead; $line .= $word; $realline .= $realword; } else { push @msgs, $realline; $line = $word; $realline = $realword; } $lead = 0; } # Leftovers! push @msgs, $realline; } return @msgs; }