It'll work, but not as you wish it to, because your XML is broken as tinita pointed out.
Changing
my $xml = '<hdsso><hpid>-----...';
to
my $xml = '<hdsso><hpid>-----...';
will not only fix your problem you asked about, it'll fix problems you haven't encountered yet. You say you're getting the data from someone else, so you'll have to convince this person to give you XML (he's currently not giving you XML) or try to fix it yourself with regexps (but you can never do a perfect job when fixing broken escapes).