in reply to Re^5: Error: Not enough space
in thread Error: Not enough space

No, system calls are NOT calls to system. Calls to system don't set $!, they set $?. System calls are function calls that interact with the system, and typically have an obvious 1-1 mapping to your systems library calls that set errno. That's C/Unix speak, but to fully understand Perl, you must understand C and Unix, as large parts of Perl are designed to work with Unix.

Functions that set $! will always return a false value on failure, and a true value on success. Never, ever use $! to determine whether something succeeded or not - the specification of your system libraries allows a function to set errno to whatever it wants in case of success (all that $! does is give you the value of errno - whose value usually isn't under Perls control). Always use the return value of the function used to determine success, and only use $! immediately after determining failure. Typically this is done by interpolating $! in the message you give with die. In your example, both print and open can set $!. But if your code reaches the test for if ($!), the open has succeeded (because you'll die if it fails). Which means that at that moment, the value of $! is utterly meaningless. No information can be derived from it.

The manual page will tell you whether a function sets $!. Functions that set $! include (but aren't limited to): open, close, print, umask, chmod, unlink, rename, mkdir, rmdir, sysopen, sysread, syswrite, and fork.