if ( $matrix[0][4][0] == 1 and $matrix[0][4][1] == 1 and $matrix[0][4][2] == 1 ... ) { # action if TRUE } #### print "it worked" if matrix_ok(\@matrix); #### sub matrix_ok { my ($matrix) = @_; { my $i = 4; for my $j (0 .. 2, 4 .. 6) { for my $k (0 .. 2) { return 0 unless $matrix->[$i][$j][$k] == 1; } } } { my $j = 4; for my $i (0 .. 2, 5, 6) { for my $k (0 .. 2) { return 0 unless $matrix->[$i][$j][$k] == 1; } } } return 1; } #### ... for my $k (MIN_DEPTH .. MAX_DEPTH) { ...