in reply to how ! operator works
You have assigned some value to $r variable. That's why it is showing as defined.
If you give
my $r;
Then it will say not defined. Rest all cases, if you assign the variable any value, that means defined.
my $r = !1;
my $r = !0;
my $r = "";