http://www.perlmonks.org?node_id=1033524


in reply to Strange bevahiour of grep function.

You don't need the test of $_mnum_prevVal in the grep as it never changes (it doesn't refer to $_), so you can move that outside the grep and that might make things easier.