use strict; use XML::Twig; my $file = 'uncle.xml'; my $twig = new XML::Twig; $twig->parsefile($file); my $root = $twig->root; my @messages = $root->children; foreach my $msg (@messages) { my $error = $msg->first_child('error'); my $result = $msg->first_child('request'); my $error_name = $error->att('name'); my $result_name = $result->att('name'); if ($error_name && $result_name) { print "ERROR : $error_name \n"; print "RESULT : $result_name \n"; } }