Вопрос 2 возможен, но вы по прихоти автора (ов) Hash :: Util:
#!/usr/bin/perl
use strict;
use warnings;
use Hash::Util qw/lock_keys/;
$SIG{__DIE__} = sub {
my $message = shift;
return unless my ($key, $file, $line) = $message =~ m{
Attempt [ ] to [ ] access [ ] disallowed [ ] key [ ] '(.*?)'
[ ] in [ ] a [ ] restricted [ ] hash [ ] at [ ] (.*?) [ ]
line [ ] (.*?).
}x;
die "$key doesn't exist at $file line $line.\n";
};
my %h = map { $_ => undef } "a" .. "z";
lock_keys %h;
my $s = $h{4};