in reply to Strange bevahiour of grep function.
Hard to read, but if you want to invert a logical clause you also have to switch and to or and invert all sub-clauses.
see De_Morgan's_laws
And consider to use List::MoreUtils 'any' instead of grep.
HTH =)
Cheers Rolf
( addicted to the Perl Programming Language)
update
s/ List::Util / List::MoreUtils /
In Section
Seekers of Perl Wisdom