Test of open and die with $!.
#!/usr/bin/perl -w $filename = "nofile"; open(TMP, $filename) or die "Can't open \"$filename\" due to $! ";