$tagstack{requirements}->[1] = { text => "A node name", attributes => {contactname => "Jane Smith", contactnumber => "555-1212" } } #### #!/usr/bin/perl -wT use strict; use XML::Simple; use Data::Dumper; my $data = XML::Simple::XMLin('./test.xml'); # show what we start with print Data::Dumper::Dumper($data); my %tagstack; my @temp; foreach my $h (@{$data->{requirement}}) { my %t; $t{text} = $h->{content}; delete $h->{content}; $t{attributes} = $h; push @temp, \%t; } $tagstack{requirement} = \@temp; # show the finished product print Data::Dumper::Dumper(\%tagstack); #### A power cord. A node name #### $VAR1 = { 'requirement' => [ { 'contactname' => 'Joe Average', 'content' => 'A power cord.' }, { 'contactnumber' => '555-1212', 'contactname' => 'Jane Smith', 'content' => 'A node name' } ] }; $VAR1 = { 'requirement' => [ { 'text' => 'A power cord.', 'attributes' => { 'contactname' => 'Joe Average' } }, { 'text' => 'A node name', 'attributes' => { 'contactnumber' => '555-1212', 'contactname' => 'Jane Smith' } } ] };