#! perl -slw use strict; use 5.010; { package debughash; require Tie::Hash; use Carp qw[ croak ]; our @ISA = qw(Tie::Hash); sub TIEHASH { bless {}, $_[0]; } sub FETCH { croak 'Non-existent key' unless exists $_[0]{ $_[1 ] }; return $_[0]{ $_[1 ] }; } sub STORE { return $_[0]{ $_[1 ] } = $_[2]; } } use constant DEBUG => 1; my %hash; tie %hash, 'debughash' if DEBUG; $hash{ 'exists' } = 1; say $hash{ 'exists' }; say $hash{ 'nonexistant' }; __END__ C:\test>junk51 Non-existent key at C:\test\junk51.pl line 32