use strict; use warnings; use XML::LibXML qw( ); my $xml = <<'XML'; 1 These spaces are to be preserved. XML my $doc = XML::LibXML->load_xml( string => $xml, no_blanks => 1 ); print $doc->toString();