Anon already gave you the correct answer to fix your problem. However, there's one other thing you should note:
You are iterating over the same range - 0..$#array2d for the two(row and column) indices. That means you should have an array that is of equal dimensions. In your case, you have a 6x5 array - make it 6x6 or 5x5.