Using the special Perl variable $! in the message passed to die
# This variable, $!, holds information about the error that occurred. #!/usr/bin/perl -w # Test of open and die with $!. $filename = "nofile"; open(TMP, $filename) or die "Can't open \"$filename\" due to $! ";