my $cols = @{$mat[0]}; #### @mat == grep { @{$_} == @{$mat[0]}; } @mat or die '@mat not well-formed';