<>; while(<>){ $_=<>; print /^0/&&(/1$/||/1 1/||y/1//>3) || /^1/&&(/0$/||/0 0/||y/0//>3) ? Yes:No,$/; }