use warnings; use strict; my %description = ( a => 'a vowel', b => 'a consonant' ); print 'a is ', check(\%description, 'a'), "\n"; print 'b is ', check(\%description, 'b'), "\n"; print '~ is ', check(\%description, '~'), "\n"; sub check { my ($href, $key) = @_; return (exists $href->{$key}) ? $href->{$key} : 'not in the alphabet'; }