use strict; use XML::TreeBuilder; my $org = <<'XML'; XML # parse the input string my $root = XML::TreeBuilder->new (); $root->parse ($org); # Insert the element my $ins = XML::Element->new ('LOCATION', name => '1stFloor'); $root->push_content ($ins); # Dump the result print $root->as_XML ();