You expression looks like having a space in the replacement portion,
Code: Perl
# Your version
$string =~ s/\s+/ /g;
# Right code
$string =~ s/\s+//g;
For replacement within PRE tags,
Code: Perl
$string =~ /<pre>([^<]+)<\/pre>/gi;
$str = $1;
$str =~ s/\s+//g;
$string =~ s/<pre>([^<]+)<\/pre>/$str/;
This will work only if there is only one occurance of pre in the string, you can also try HTML::Parse for this purpose.