sub _copy { my $this = shift; if (not ref $this) { $this } elsif (ref $this eq "HASH") { +{map { $_ => _copy($this->{$_})} keys %$this} } elsif (ref $this eq "ARRAY") { [map _copy($_), @$this] } elsif (ref $this eq "CODE") { # do some processing here, the following is a # placeholder 'CODEREF' } else { Carp::croak "What's a " . ref $_ . "?" } }