my $submitted_pw = $_; my $pw; foreach my $stored_pw (@stored) { if ($submitted_pw eq $stored_pw) { $pw = $stored_pw and last; #exit the loop if we found a match } } # If $pw wasn't set in the loop, create a new password $pw ||= join(@chars[map{rand @chars} (1..17)];