$text = "test of  this # ? my 0923 5834t674"; .... .. .......... . . .. .... ........ #### if ($text =~ $nbsp) { $text =~ s/(.*)$nbsp(.*)//g; # ( ) PUTS TEXT INTO $1, $2, etc. $tex1 = $1; # WHAT COMES BEFORE THE PRE TAG $tex2 = $2; # WHAT COMES AFTER $tex1 =~ s/[^ ]/$repl/g; # BLANK OUT, EXCLUDING SPACES $tex2 =~ s/[^ ]/$repl/g; $text = "$tex1$nbsp$tex2"; } else { $text =~ s/[^ ]/$repl/g; } print "$text\n";