In Perl, the special variable $! contains the error number or error string from the last system call or library function that failed. When used in a numeric context, it returns the error code; in string context, it returns the corresponding error message.