#### use strict; my $xs = new XML::Simple; my $xml = $xs->XMLin("$folder_path\\policies.xml", forcearray => 1, keyattr => ['policies']); my $hash_add = [{ $cat => [{ 'name' => "$name", 'link_name' => "$link_name", 'description' => "$desc", 'date' => "$today_date" }] }]; # Add to hash push (@{$xml->{'policies'}}, $hash_add); print "Content-type: text/html\n\n"; # Sort hash @{ $xml->{'policies'} } = sort { "\L$a->{name}" cmp "\L$b->{name}"} @{ $xml->{'policies'} }; use Data::Dumper; print Dumper($xml); $xs->XMLout($xml, outputfile => "$folder_path\\policies.xml", attrindent => 1); #### 'policies' => [ { 'New' => [ { 'date' => '28-8-104', 'name' => 'Test3', 'link_name' => 'Test3.doc', 'description' => 'asdf' } ], 'policies2' => [ { 'name' => 'General Admit to GPRMC', 'link_name' => 'General Admit to GPRMC.doc', 'description' => '', 'catagory' => 'General' } ], 'Newer' => [ { 'date' => '28-8-104', 'name' => 'Whatever', 'link_name' => 'Whatever.doc', 'description' => 'asdf' } ] }, [ { 'Newer' => { 'date' => '28-8-104', 'name' => 'whatever', 'description' => 'something', 'link_name' => 'whatever.doc' } } ] ] ####