#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t = XML::Twig->new(); $t->parsefile('x.xml'); my @errors = map { my %d = map { (my $tag = $_->tag()) =~ s/^m://; $tag => $_->text() } $_->children(); \%d } $t->get_xpath('//m:error'); use Data::Dumper; print Dumper \@errors; #### $VAR1 = [ { 'col' => '66', 'message' => 'document type does not allow element "LINK" here', 'line' => '11' }, { 'col' => '41', 'message' => 'document type does not allow element "LINK" here', 'line' => '14' }, { 'col' => '4', 'message' => 'document type does not allow element "META" here', 'line' => '21' } ];