use strict; use warnings; use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { offer => sub { printf("%s,%s,%s\n", $_->att('id'), $_->first_child('f1')->text(), $_->first_child('f2')->text(), ); } } ); $twig->parsefile('a.xml');