use strict; use warnings; use Data::Rmap qw(:all); my $initial = [ note => [ shopping => [ 'item' ] ] ]; use Data::Dumper; # build a list of shopping items ** for reuse ** my @shopping_items; for my $item qw(bread butter beans) { push @shopping_items, [ item => $item ]; } my ($dump) = rmap_array { # If we get an arrayref whose first element is 'shopping' if ($_->[0] eq 'shopping') { # Make the second element the shopping list $_->[1] = [ @shopping_items ]; # No need to drill down any further cut($_); } else { # if the arrayrefs first element is not 'shopping' # then simply pass it through $_; } } $initial; warn Dumper($initial, $dump);