A parity measurement on two qubits, each consisting of a single atom in a cavity, can be realized by measuring the phase shift of a probe beam which interacts sequentially with the two qubits, but imperfections lead to decoherence within the subspaces of a given parity. We demonstrate that a different setup, where the probe light interacts repeatedly with the qubits, can reduce the rate of decoherence within the odd-or the even-parity subspace significantly. We consider both the case of a resonant and the case of a nonresonant light-atom interaction and find that the performance is comparable if the parameters are chosen appropriately.