use strict; use warnings; use English; use XML::Twig; my $xmlFile = "demo.xml"; my $t = XML::Twig->new( pretty_print => 'indented_a', keep_atts_order => 1, twig_handlers => { q(myconfig/myobj[string(uniqueName)=" objA "]/myattributes/attribB) => \&getfoo, } ); $t->parse ( \*DATA ); $t->print; exit 0; sub getfoo { my ($t, $e) = @_; print "text=", $e->text(), "' tag='", $e->tag(), "' path='", $e->path(), "' parentTag='", $e->parent->tag(), "'\n"; } __DATA__ objA fooA fooB objB fooA fooB