sub text2mush { local($in)=shift; $in =~ s/\t/\%t/g; # convert tabs while ($in =~ /((.)(\2){4,})/) { # while at least five of anything $matched = $1; $matchedchar = $2; $i = index($in,$matched,0); $l = length($matched); if ($matchedchar eq " ") { # it was spaces substr($in,$i,$l)="[space($l)]"; } else { substr($in,$i,$l)="[repeat($matchedchar,$l)]"; } } $in =~ s/ /\%b\%b/g; # two spaces becomes expanded to 4. $in .= "\%r" unless $in =~ s/$/\%r/; # convert newline to %r. return $in; } 1;