$tree[0] = $arr[0]; my @copy = @{$arr[1]}; $tree[1] = \@copy; ... my ($index) = grep { $tree->[$_] eq $treeElement } 0..scalar(@$tree)-1; my @copy = @$subNg; splice @{$tree}, $index + 1, 0, \@copy;