if ($text =~ /<\/Mil[^>]*>(.*)\x9D/i) { my $string = $1; $string =~ s/[\x90\x8F]//g; $text =~ /(<\/Mil[^>]*>).*(\x9D)/$1$string$2/i; }