use warnings FATAL => 'substr'; ... eval { substr($str, $really_big_number) }; if ($@) { # an exception is now thrown }