use strict; use warnings; use XML::TreeBuilder; my $xml = < XML my $root = XML::TreeBuilder->new (); $root->parse ($xml); for my $group ($root->look_down ('_tag', 'author-group')) { my @auths = $group->look_down ('_tag', 'auth'); my $newRoot = HTML::Element->new ('xxx'); $_->detach () for @auths; $newRoot->push_content (@auths); $group->unshift_content ($newRoot); } print $root->as_XML (); ####