use XML::Simple qw(:strict); $config = XMLin('config.xml', KeyAttr => {item=>'filename'}, ForceArray => ['item']); #### 0 AMEX test 1 bla test1 2 alb test2 #### for (my $i = 0; $i < $theNumberOfItems; $i++) { print $config->{item}[$i]->{destination_dir}; } #### for (my $i = 0; $i < $theNumberOfItems; $i++) { print $config->{item}{$i}->{destination_dir}; }