my %people = (); while (blah) { ## do something $people{$fname}{$lname}++; } my $search_term = 'John'; if (exists $people{$search_term}){ # do stuff. }