sub main { my $input_qfn = "input.file"; my $pattern_qfn = "pattern.file"; my %emailAddresses; { open(my $input_fh, '<', $input_qfn) or die("Can't open input file \"$input_qfn\": $!\n"); while (<$input_fh>) { chomp; my ($userName, $emailAddress, $division, $fullName) = split /\|/; ++$emailAddresses{$emailAddress}; } } open(my $pattern_fh, '<', $pattern_qfn) or die("Can't open pattern file \"$pattern_qfn\": $!\n"); while (<$pattern_fh>) { chomp; if ($emailAddresses{$_}) { print "$_ exists in the input file\n"; } else { print "$_ doesn't exist in the input file\n"; } } }