my $twig= XML::Twig->new( twig_handlers => { title => \&title }) ->parsefile( "foo.xml"); sub title { my( $twig, $title)= @_; # return 1 (true) if you can have other handlers on the # title, otherwise it doesn't matter what you return # see the doc for twig_handlers return 1 unless( $title->root->matches( 'gutbook'); $title->set_tag( 'tit'); }