my $found = 0 foreach my $key (keys %name_hash) { if ($key =~ m/$_/i) { print "The username is $username and the password is $password, please enter another name to search\n"; $found = 1; } } if (!$found) { print "I'm sorry, there is no one here by that name, please try another name or type exit to end.\n" }