use Storable qw(freeze thaw); sub rec_walk { my $hash = shift; foreach (keys %$hash) { if (ref $hash->{$_} eq 'CODE') { $hash->{$_} = freeze $hash->{$_} } elsif (ref $hash->{$_} eq 'HASH') { $hash->{$_} = rec_walk($hash->{$_}) } } $hash } my %hash = (...); print Dumper rec_walk(\%hash);