Unfortunately some problems have slipped through because your code doesn't use strict; If you did that you'd see that the $line3 variable is undefined, and others lack lexical scoping.

Update:

Felt a bit guilty for the brevity of my original answer, so here is a quick example of code that works to produce the output you were expecting. It may need some tweaking as you see fit

use strict; use warnings; # Load the acceptable ids from file2 into a hash my %ids; open my $idfile, '<', 'file2' or die $!; for (<$idfile>) { $ids{$1} = 1 if m/Accept\s+=>\s+(\S+)/; } close $idfile; # Scan file1 printing each line where the ID matches one found in our +hash open my $datafile, '<', 'file1' or die $!; for (<$datafile>) { chomp; my ($id) = m/ID\s+(\S+)/; print "$_\n" if exists $ids{$id}; } close $datafile;

Output:

ID John06/ext $work(b05bfn00ld0p7)/b05bfn00ld0p7 ; #<= b05bfn00ld0s0 S +ize:INFINITY ID lily099/poli $work(b05bfn00ld0p7)/b05bfn00ld0p7 ; #<= b05bfn00ld0s0 + Size:INFINITY ID lily099/poli $wwrk(b05bfn00ld0p8)/b05bfn00ld0p8 ; #<= b05bfn00ld0s0 + Size:INFINITY

In reply to Re: Perl: How to print unmatched data after comparison of two files? by Loops
in thread Perl: How to print unmatched data after comparison of two files? by WWq

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.