I think you want the last function.
my $match = 0; # We haven't got a match yet.
while ($lines = <PSWD>){
($user,$pswd,$userID,$groupID,$info,$home,$shell) = split ':', $lin
+es;
if ($username eq $user) {
print "Checking username... MATCH\n";
if ($passwd eq $pswd){
print "Checking password... MATCH\n";
}
else {
print "Password does not match!\n";
}
$match = 1; # We have found a match
last; # So stop looping already!
}
}
unless ($match) {
print "\"$username\" does not match any users in our database!\n";
}
Update: I have also moved that else outside of the loop as an unless block.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'