use strict; use warnings; use XML::XPath; my $xp = XML::XPath->new(filename => 'mdlist.xml'); my @mds = map { $_->getAttribute('name') } $xp->findnodes('/md_map/md[@name]'); for my $dir (@mds) { # create $dir if applicable }