use XML::Smart qw( ); my $xml = XML::Smart->new(); $xml->{foo}{bar}{empty} = {}; print scalar $xml->data();