eval { foo(); }; if ( $@ ) { # handle the error the error is in $@ }