#Consider the output of the following my %family_name = ( "Alis" => "Williams", "Sara" => "McAwesome", "Serena" => "Anderson", ); my $key = keys %family_name; print $key; print "\n"; my $val = values %family_name; print $val; print "\n"; my @keys = keys %family_name; print "@keys\n"; my @values = values %family_name; print "@values\n"; #### use strict; use warnings; #The hash is populated as in the OP code above #The user is prompted to enter a name my @keys = keys %family_name; my @values = values %family_name; #The arrays members are in the same order the hash #is stored in the memory and not necessarily the #order in which the hash has been populated. my $index; for(my $i = 0; $i<=$#keys; $i++){ #looping through @keys if($name eq $keys[$i]){ $index = $i; #to retain the iterator value to $index retHashVal($name, $index); } } sub retHashVal{ my ($n,$i) = @_; print "$n is already there and her family name is $values[$i]\n"; } ####