perl -MXML::Twig -e "BEGIN{$f=shift @ARGV} map{ XML::Twig->new(twig_handlers => { 'newitems/book' => sub { push @content, $_; $_->cut }})->parsefile($_) }@ARGV; XML::Twig->new(pretty_print=>'indented',twig_handlers => {'catalog' => sub {foreach my $content ( @content ) {$content->paste( last_child => $_ );}}})->parsefile($f)->flush " current_catalog.xml new_items.xml #### perl -MXML::Twig -e "map{$t=XML::Twig->new(twig_handlers=>{$s?('catalog'=>sub{foreach$c(@c){$c->paste(last_child=>$_)}}):('newitems/book'=>sub{push@c,$_;$_->cut})})->parsefile($_);$s++;}@ARGV;$t->flush" newbook.xml catalog.xml