#!/usr/bin/perl use warnings; use strict; use XML::XSH2; use Data::Dumper; xsh << '}'; open 942690.xml ; for my $num in /Servicelist/Service/@Num { for my $s in $num/..//@Service perl { push @{ $hash->{$num->value} }, $s->value } ; } } print Dumper $XML::XSH2::Map::hash;