use strict; use warnings; use XML::Twig qw( ); my $twig = XML::Twig->new( twig_roots => { 'Application[Properties/Timeout]' => sub { my ($t, $elt) = @_; print("$elt->{att}{Name}\n"); $t->purge; } }, ); $twig->parsefile('a.xml'); #### use strict; use warnings; use XML::Twig qw( ); my $twig = XML::Twig->new( twig_handlers => { 'Application/Properties/Timeout' => sub { my ($t, $elt) = @_; print($elt->parent->parent->att('Name'), "\n"); }, }, ); $twig->parsefile('a.xml');