$! set when a system call fails.
open my $fh, '<', '/foobarbaz' or die $!
This will result in the output "There is no such file or directory."
$@ contains the argument passed to die . Therefore:
eval { open my $fh, '<', '/foobarbaz' or die $! }; if ( $@ ) { warn "Caught exception: $@ "; }
It makes no sense to check $@ without using any form of eval , and it makes no sense to check $! when you did not call a function that could set it in case of an error.
innaM source share