use XML::Twig; my $t= XML::Twig->new( twig_handlers => { 'editor[@role="editor"]' => sub { print $_->text() }, }); $t->parsefile( 'yourfile.xml' );