# call the superclass to render the simple data in the hashref my $lol = do { local $self->{data} = \%tmpdata; super(); }; # now rewrite part of the loltree with repetition my @newlol; for my $invoice_line ( @{$array_rows_for_single_invoice} ) { my $aref = [ InvoiceLineAdd => [ ItemRef => [ ListID => $invoice_line->{product_listid} ] ], [ Amount => $invoice_line->{amount} ], ]; push @newlol, $aref; } my ($dump) = rmap_array { if ( $_->[0] eq 'InvoiceAdd' ) { use List::MoreUtils qw(first_index); my $i = first_index { ref $_ and $_->[0] eq 'SetCredit' } @$_; splice @$_, ++$i, 1, @newlol; # No need to drill down any further cut($_); } else { $_; } } $lol;