while () { ($userName,$emailAddress,$division,$fullName) = split(/\|/, $_); while (@lines) { my $pattern = pop @lines; $pattern=~s/\n//g; if ($emailAddress =~ /$pattern/) { print $pattern . " exists in " . $emailAddress."\n"; } else { print $pattern . " no match " . $emailAddress."\n"; last; } } #### my $exists = 0; while () { ($userName,$emailAddress,$division,$fullName) = split(/\|/, $_); while (@lines) { my $pattern = pop @lines; $pattern=~s/\n//g; if ($emailAddress =~ /$pattern/) { $exists = 1; last; } } if ($exists) { print "$emailAddress exists\n"; } else { print "$emailAddress doesn't exist"\n"; } #### sub main { my $input_qfn = "input.file"; my $pattern_qfn = "pattern.file"; my %patterns; { open(my $pattern_fh, '<', $pattern_qfn) or die("Can't open pattern file \"$pattern_qfn\": $!\n"); while (<$pattern_fh>) { chomp; ++$patterns{$_}; } } 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 /\|/; if ($patterns{$emailAddress}) { print "$emailAddress exists in the pattern file\n"; } else { print "$emailAddress doesn't exist in the pattern file\n"; } } } #### David@domain.com exists in the pattern file Cory@domain.com doesn't exist in the pattern file Tania@domain.com exists in the pattern file Geoffrey@domain.com doesn't exist in the pattern file