in reply to Trapping a warning

perlfaq7.pod has a very related advice:
=head2 How can I catch accesses to undefined variables/functions/metho +ds? The AUTOLOAD method, discussed in L<perlsub/"Autoloading"> and L<perltoot/"AUTOLOAD: Proxy Methods">, lets you capture calls to undefined functions and methods. When it comes to undefined variables that would trigger a warning under C<-w>, you can use a handler to trap the pseudo-signal C<__WARN__> like this: $SIG{__WARN__} = sub { for ( $_[0] ) { # voici un switch statement /Use of uninitialized value/ && do { # promote warning to a fatal die $_; }; # other warning cases to catch could go here; warn $_; } };

Adopt that code, and you will be able to "intercept" your warnings and use a value of "$!" at your will
Also, do not forget to protect your code by

try { } if ($@) { ... }
Jim