#!/usr/bin/perl use strict; use XML::Twig; my $input_xml = 'big.xml'; # tags to keep my $re = qr/u_application_i|u_ci_id|sys_class_name|name|ip_address/; my $twig = 'XML::Twig'->new( twig_handlers => { result => \&record }, ); open my $fh,'>','small.xml' or die "$!"; $twig->parsefile($input_xml); sub record { my ($e,$t) = @_; for ($t->children){ $_->cut unless ($_->name =~ $re); } $t->flush($fh,pretty_print => 'indented'); } #### 10.10.10.10 lnxnmsprag27 lnxnmsprag27 CI10110212 cmdb_ci_linux_server