$My_Value = 'SuperUser'; # assumption for this exercise foreach $item (keys %Myhash){ # $item = 'SuperUser' first pass through if ($item eq $My_Value) { foreach $iteminitem (sort(keys %{$Myhash{'SuperUser'}})){ # $iteminitem = 'Username' first pass through foreach $iteminitem1 (sort(keys %{$Myhash{'SuperUser'}{'Username'}})){ ## Here's the problem: $Myhash{'SuperUser'}{'Username'} = 2 if ($iteminitem1 eq 'name' && $user_number == $Myhash{$item}{$iteminitem}{$iteminitem1}) { my $User = $iteminitem; } } } } } #### if (ref $iteminitem eq 'HASH') { foreach $iteminitem1 (sort(keys %{$Myhash{$item}{$iteminitem}})){ .... } }