As @choroba pointed out, those aren’t entity references, but character references.
In any case, round-tripping XML/HTML/SGML content is difficult (entities, char refs, whitespace), as most parsers are geared toward access, rather than editorial preservation.
Depending on your actual goal, a different parser or parsing mode could help. Look into XML::LibXML::Reader
or other tools that provide access to inner/outer XML.