use strict; use XML::Twig; my $sel = 'title'; my $ign = 'title/title/title'; my $twig = XML::Twig->new( ignore_elts => { "$ign" => 1}, twig_handlers => { "$sel" => \&title}, pretty_print => 'indented' ); $twig->parsefile('1.xml'); $twig->print; sub title { my ($twig, $tit) = @_; $tit->set_gi('tit'); }