use XML::Simple; $data = XMLin( \*DATA, KeepRoot => 1, ForceArray => [ qw/attribute/ ] ); @attrs = map { $_->{category} } # We want the category value map { @{ $_->{attributes}{attribute} } } # for each attribute values %{ $data->{dataschemas}{dataschema} }; # in all dataschemas. print "@attrs\n"; __DATA__ #### foreach my $dataschema ( values %{ $data->{dataschemas}{dataschema} } ) { foreach my $attr ( @{ $dataschema->{attributes}{attribute} } ){ print "category is: ", $attr->{category}, "\n"; } }