#!/usr/bin/env perl use strict; use Getopt::Long; use YAML qw(LoadFile); use Data::Dumper; my $file; GetOptions ( "file=s" => \$file); if ( $file ) { $SIG{__DIE__} = sub { die("My error: ", @_); }; $SIG{__WARN__} = sub { warn("My warning: ", @_); }; open my $fh, '<', $file or die "Cannot open target file\n"; #THIS ERROR IS CATCHABLE my $config = LoadFile($fh) or warn("YAML parsing error\n"); #CANNOT CATCH ERROR #or warn "YAML parsing error\n"; #CANNOT CATCH ERROR print Dumper(\$config), "\n"; } else { die "Syntax: $0 [-f,--file] [YAML_FILE]"; }