# perldoc > exit

---
type: CommandReference
command: exit
mode: perldoc
section: perlfunc
source: perldoc
---

## Quick Reference

- `exit 0` — Exit with success status
- `exit 1` — Exit with error status
- `exit $status` — Exit with a specific numeric status
- `exit` — Equivalent to `exit 0`
- `exit if $cond` — Conditional exit

## Name

**exit** — Evaluates EXPR and exits immediately with that value.

## Synopsis

perl
exit EXPR
exit
## Description

`exit` evaluates EXPR and exits immediately with that value. If EXPR is omitted, exits with status 0. The only universally recognized values are 0 (success) and 1 (error); other values are platform-dependent.

**Important:** `exit` does not always exit immediately. It calls any defined `END` routines first, and object destructors are also run before the real exit. `END` routines and destructors can change the exit status by modifying `$?`. To bypass `END` and destructor processing, use `POSIX::_exit($status)`.

Do not use `exit` to abort a subroutine if any caller might want to trap the error. Use `die` instead, which can be caught by `eval`.

## Examples

perl
my $ans = <STDIN>;
exit 0 if $ans =~ /^[Xx]/;
## See Also

- [`die`](perlfunc.md#die)
- [`END` blocks in perlmod](perlmod.md)
- [`POSIX::_exit`](POSIX.md)
- [Portability of `exit` in perlport](perlport.md)