my $file = '/home/bob/db.txt'; open my $fh, $file or die "$file: $!"; my $pass; while (<$fh>) { chomp; my @fields = split /\s+/; if ($fields[0] eq 'user@example.com') { $pass = $fields[1]; last; } } close $fh;