#!perl use strict; use XML::Twig; my $xml = q! 111 234 111 abc !; my $t = XML::Twig->new( twig_handlers => {'test/book[string()=~/abc/]'=> \&book} ); $t->parse($xml); sub book { my($t,$book) = @_; $book->parent->print; print "\n"; }