use strict; use warnings; #always a good idea! #... some loop that sets $inputFile to the file path ... eval { # try to open the file, die and explain the problem on failure open my $INFILE, '<', $inputFile or die "Cannot read '$inputFile': $!" #.. do I/O on $INFILE (e.g. <$INFILE>, [doc://sysread], etc.) ..# }; if ($@) { # this catches the message from any "die" in the eval{} block # the message will be in the scalar '$@'; print "!: Error while working on file-> $@" } #.. move on to the next file ..#