title: Comparing Two text files in perl and output the matched result
body: <p>I want to compare two text files that i have generated from one of the perl script that i wrote.
  I want to print out the matched results from those two text files. I tried looking at couple of answers and questions that people have asked on stackoverflow but it does not work for me. Here is what i have tried.</p>
  
  <pre><code>my $file1 = "Scan1.txt";
  my $file2 = "Scan2.txt";
  my $OUTPUT = "final_result.txt";
  my %results = (); 
  open FILE1, "$file1" or die "Could not open $file1 \n";
     while(my $matchLine = &lt;FILE1&gt;)
         {   
           $results{$matchLine} = 1;
      }
      close(FILE1); 
      open FILE2, "$file2" or die "Could not open $file2 \n";
     while(my $matchLine =&lt;FILE2&gt;) 
          {  
      $results{$matchLine}++;
          }
      close(FILE2);  
      open (OUTPUT, "&gt;$OUTPUT") or die "Cannot open $OUTPUT \n";
      foreach my $matchLine (keys %results) { 
      print OUTPUT $matchLine if $results{$matchLine} ne 1;
      }
      close OUTPUT;
  </code></pre>
  
  <p>EXAPLE OF OUTPUT THAT I WANT</p>
  
  <p>FILE1.TXT
  data 1
  data 2
  data 3</p>
  
  <p>FILE2.TXT
  data2
  data1</p>
  
  <p>OUTPUT
  data 1
  data 2</p>