( $sum |= substr $all, $_ ) =~ tr/1357/2468/ for 1, 2, $w, $w + 2, ($w << 1), ($w << 1) + 1, ($w << 1) + 2; # other 7 neighbors