or download this
sub CollapseWhitespace{@_ or return'';my$T=shift;defined$T
or return'';my$L=length($T);$L or return'';my$c;my$N=0;my$P
=0;my$U=1;for(my$i=0;$i<$L;$i++){$c=vec($T,$i,8);if($c<33){
$U=0;if($N++==1){vec($T,$P++,8)=32;}}else{$N=0;$U or vec($T
,$P,8)=$c;$P++;}}return$U?$T:substr($T,0,$P);}