use warnings; use strict; use XML::Twig; my $xml = < four one two three XML my $twig = XML::Twig->new( twig_handlers => { 'html/head/title' => sub { print $_->text(), "\n" } }, ); $twig->parse($xml); __END__ one