in reply to selective warnings

What warnings do you get exactly? Surely not from the if (!$r):
$ perl -le 'use warnings; if (!undef) { print "foo" }' foo

No warning from !undef.

So first you should find out what's the cause for the warning.

Then you can read perllexwarn on how to disable warnings selectively.