$XmlRef->{$keyname}{'devices'}{'dev'.$cnt}{'param'} = []; for my $foo(keys %{$userref->{$key}{'hash'}}) { push @{ $XmlRef->{$keyname}{'devices'}{'dev'.$cnt}{'param'} } , {id => $foo, content => $userref->{$key}{'hash'}{$foo}} ; $i+=1; }