in reply to update required for subroutine

As far as I can tell the only difference between the current output of your code and the output you indicate that you want is the hash references are nested in array references. That being the case the following version of the call back sub does the trick:

sub { my ($key, $val, $href) = @_; if (exists $repl{$key}) { my $newkey = $repl{$key}; $val = [$val] if ref ($val) eq "HASH"; $href->{$newkey} = $val; delete $href->{$key}; }

Note the $val = [$val] ... line.

True laziness is hard work