use warnings; my $days = 'oops'; eval { local $SIG{__WARN__} = sub { die "not numeric" }; $days += 0; }; if ($@) { # at this point $days will be zero # and $@ will be "not numeric" }