use strict; use warnings; use XML::Twig; my $twig=XML::Twig->new( twig_handlers => { 'termEntry/langSet'=>sub{print $_[1]->att('xml:lang'), ": ", $_[1]->first_child('termGrp')->text, "\n" } }, ); $twig->parse( \*DATA ); __DATA__ Ciao Ricerca scientifica research università university