### $#array is the highest index in @array. my $yMax = $#lt; ## $#{ ... } is the highest index in the array referenced by ... ## $array[ -1 ] is the last element in the @array ## So the following sets $xMax to highest index of the array (reference) ## in the last element of @lt. Ie. The longest subarray. my $xMax = $#{ $lt[-1] }; ## Iterate through each the subarrays except the last which does need padding for my $y ( 0 .. $yMax -1 ) { ## for $lt[ $y=0 ] ([1]), we need to add elements $y+1..$xMax (1..3) ## for $lt[ $y=1 ] ([2,3]), we need to add elements $y+1..$yMax (2..3) ## And the value we add at $lt[ $y ][ $x ] comes from $lt[ $x ][ $y ]. for my $x ( $y+1 .. $xMax ) push @{ $lt[ $y ] }, $lt[ $x ][ $y ]; } }