Have you learned about hashes yet? You are in need of an algorithm, and the one that you need will most likely involve the use of a hash. Something like this:
declare a hash (e.g. "my %lines." open the first input file while reading the first input one line at a time use the line as a hash key and assign "1" as the hash value close the file open output.file1 to hold "matching lines" open output.file2 to hold "distinct lines" open the second input file while reading the second input one line at a time if the current line exists as a hash key and the hash value is "1" print this line to the "matching lines" file increment the hash value otherwise print this line to the "distinct lines" file (maybe include the f +ile name) having read all input, now loop over all the keys of the hash if the hash value assigned to this key is still "1" print this hash key to the "distinct lines" file (maybe include t +he file name)
I think you'll find that the actual perl code for that will be somewhat shorter than what I've written, but (since I assume this is homework) you should write the code. There are lots of places to read about hashes in Perl. Have you checked the Tutorials here at the Monastery?

In reply to Re: comparing contents of the file by graff
in thread comparing contents of the file by Ms.Ranjan

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.