foreach $row (0..$#A){ #array row length foreach $col (0 .. ($#{$A[0]} - 1) ) { #array width less one $b->[$row*2][$col] = $a->[$row][$col]; # copy all but last ele over } $b->[($row *2) +1][0] = $a->[$row][$#{$A[0]}]; #now copy last #there are twice as many rows so we double the row index }