use warnings; use strict; use XML::LibXML; use open qw/:std :utf8/; my $xml = <<'END_XML'; END_XML my $doc = XML::LibXML->load_xml(string => $xml) or die; $doc->documentElement->appendText("\x{20AC}"); open my $fh, '>', '/tmp/one.xml' or die $!; print $fh $doc->toString; close $fh; $doc->toFile('/tmp/two.xml');