while (<$fh>) { chomp; my ($user,$passwd,$db,$server) = split /:/; if ($db eq $desired_db && $user eq $desired_user) { ... last; } }