#!/usr/bin/perl -- use strict; use warnings; my $fudge = { "Orders" => { "GeneralDescription" => "General Instruction Section", "order1" => { "type" => "print" }, "order2" => { "type" => "print" } } }; use Data::Dump qw' dd '; dd $fudge; #~ $xmlrecord #~ ...{GeneralDescription} = ...('/Orders/GeneralDescription'); #~ ...{order1} = ...('/Orders/order1/type/@type'); #~ ...{order2} = ...('/Orders/order2/type/@type'); my @paths = fudge( $fudge ); dd \@paths; my %xmlrecord = map { $$_[0] => ($$_[1]) } @paths; dd \%xmlrecord ; use Data::Diver qw' Dive '; sub fudge { my $ref = shift; my @paths; if( my $orders = Dive $ref, 'Orders' ){ while( my( $key, $value ) = each %$orders ){ if( ref $value ){ my( $type ) = keys %$value; push @paths, [ $key, join '/', 'Orders', $key, $type, '@'.$type ]; } else { push @paths, [ $key, join '/', 'Orders', $key ]; } } } return @paths; } __END__ { Orders => { GeneralDescription => "General Instruction Section", order1 => { type => "print" }, order2 => { type => "print" }, }, } [ ["GeneralDescription", "Orders/GeneralDescription"], ["order2", "Orders/order2/type/\@type"], ["order1", "Orders/order1/type/\@type"], ] { GeneralDescription => "Orders/GeneralDescription", order1 => "Orders/order1/type/\@type", order2 => "Orders/order2/type/\@type", }