title: Use Perl to search for a match between two files
body: <p>I have two files: <code>file1.txt</code> and <code>file2.txt</code>. Both contains lines in this format:</p>
  
  <p><strong>file1</strong></p>
  
  <pre><code>name1:value1
  </code></pre>
  
  <p><strong>file2</strong></p>
  
  <pre><code>name2:value2
  </code></pre>
  
  <p>I want to check if <code>value1</code> is found in <code>list2</code> (in the <code>name2</code> string) </p>
  
  <p>I have this function:</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings;
  use Parallel::ForkManager;
  
  sub loadf($);
  
  print "Starting main program\n";
  my @list1 = loadf("list1.txt");
  my @list2 = loadf("list2.txt");
  
  my $workernum = 10; 
  open(OK, '&gt;&gt;', 'valid.txt');
  open(ER, '&gt;&gt;', 'invalid.txt');
  $pm = new Parallel::ForkManager($workernum);
  
  my $cnt = 0;
  foreach $line (@list1) {
      $cnt++;
      my $pid = $pm-&gt;start and next;
      my @data1 = split(":", $line);
      my $name1 = $data1[0];
      my $value1 = $data1[1];
      my @data2 = split(":", $list2);
      my $name2 = $data2[0];
      my $value2 = $data2[1];
  
      if (/$value1/i ~~ @list2) 
      {
          print OK $name1 . " - " . $value2 . "\n";
          print " [+] Found: " . $name1 . " - " . $value2 . "\n";
      }
      else
      {
          print ER $name1 . "\n";
          print " [x] Unknown: " . $name1 . " - " . $value1 . "\n";
      }
      $pm-&gt;finish;
  }
  
  close(OK);
  close(ER);
  print "\n*** Finished ***\n";
  
  sub loadf($) {
      my @file;
      open(FILE, $_[0] . "\n") or die("[+] Couldn't open " . $_[0] . "\n");
      @file = &lt;FILE&gt;;
      close(FILE);
      return @file;
  }
  
  __END__
  </code></pre>
  
  <p>which is not working. What am I doing wrong ?</p>