#!/usr/bin/perl my $xml_str1 = ' USA UK CANADA MEXICO INDIA CHINA '; parse_xml($xml_str1); sub parse_xml { use XML::LibXML; no warnings; my $Country = (); my @List = (); my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($_[0]); foreach my $ca_isins ($doc->findnodes('/List//Events/Event')) { my ($titleCountry) = $ca_isins->findnodes('./Country'); $Country = $titleCountry->to_literal . "\n"; my ($widValue) = $ca_isins->findvalue('../../@Wid'); $Country = $titleCountry->to_literal . "|" . $widValue . "\n"; push (@List, $Country); } print "@List"; }