I can't see my error here Monks!!!

I just need to grep where data from the pattern file exists in the input file.

input.file looks like this :
David@domain.com|David@domain.com|J|ABBASS, DAVID JOHN|
Cory@domain.com|Cory@domain.com|E|ABBOTT, CORY J|
Tania@domain.com|Tania@domain.com|F|ABBOTT, TANIA LEE|
Geoffrey@domain.com|Geoffrey@domain.com|N|ABBOTT, GEOFFREY BRYAN|

pattern.file looks like this :
Randall@domain.com
David@domain.com
Rob@domain.com
Tania@domain.com

Script should tell me that Tania@ and David@ exist :

sub main { my $filename = "input.file"; open (my $valuesFile, '<', 'pattern.file') or die "Failed: $!\n"; while (<$valuesFile>) { push (@lines, $_); } open(INPUT, $filename) or die "Cannot open $filename"; while (<INPUT>) { ($userName,$emailAddress,$division,$fullName) = split(/\|/, $_); while (@lines) { my $pattern = pop @lines; $pattern=~s/\n//g; #print "pattern: ".$pattern."address: ".$emailAddress."\n"; if ($emailAddress =~ /$pattern/) { print $pattern . " exists in " . $emailAddress."\n"; } else { print $pattern . " no match " . $emailAddress."\n"; last; } } } close(INPUT); close $valuesFile; }

In reply to Look for pattern in file. ???? by davidinottawa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.