#!perl use strict; use warnings; use XML::Simple; use Data::Dump 'pp'; my @xml=(); # 2 devices $xml[0] = ' '; # 1 device $xml[1] = ' '; # run for each xml for my $i (0..1){ my $heap = XMLin($xml[$i]); for my $name (keys %{$heap->{cfg}->{device}}){ push @{ $heap->{cfg}->{devices}},$name; } print pp $heap; print "\n-----------------------\n"; foreach my $name (@{ $heap->{cfg}->{devices} }) { my $CFG = $heap->{cfg}->{device}->{$name}->{localfile}; print "$CFG\n"; } print "-----------------------\n"; }