#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash = ( key1 => 'value', key2 => undef, key3 => {}, ); foreach my $key (qw(key1 key2 key3)) { print "\$hash{$key} exists: " . (exists $hash{$key} ? "yes" : "no") . "\n"; print "\$hash{$key} is defined: " . (defined $hash{$key} ? "yes" : "no") . "\n"; print "\$hash{$key} is defined and not exist: " . ((!defined $hash{$key} and !exists $hash{$key} ) ? "yes" : "no") . "\n"; } __END__ $hash{key1} exists: yes $hash{key1} is defined: yes $hash{key1} is defined and not exist: no $hash{key2} exists: yes $hash{key2} is defined: no $hash{key2} is defined and not exist: no $hash{key3} exists: yes $hash{key3} is defined: yes $hash{key3} is defined and not exist: no