in reply to function or something

If I understand you correctly, you want to set $!. From the docs (emphasis mine):

If used numerically, ($!) yields the current value of the C errno variable, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used an a string, yields the corresponding system error string. You can assign a number to $! to set errno if, for instance, you want "$!" to return the string for error n, or you want to set the exit value for the die() operator.

Update: Now that I reread the question, I can't tell if you're trying to return an exit value from a program (as I initially thought) or simply trap a fatal error within the same program. Please elaborate if I misunderstood.