use strict; use warnings; use JSON; my %dispatch = ('' => sub { print "$_[0]\n"; }, 'HASH' => sub { for my $key (keys %{$_[0]}) { search_and_replace_in_hash( $_[0]->{$key} ); } }, 'ARRAY' => sub { search_and_replace_in_hash( $_ ) for @{$_[0]}; }, 'default' => sub { my ( $element, $op ) = @_; print STDERR ref($element).": unknown type of reference\n" }, ); sub search_and_replace_in_hash { &{ $dispatch{ ref($_[0]) } // $dispatch{'default'} }(@_); } my $data = <new()->decode( $data ); search_and_replace_in_hash( $data );