title: Save all Data in array, Filter out duplicated Data, Compare Data between arrays and Removed the matched Data
body: <p>I have some problems regarding my script.
  The problems are:</p>
  
  <ol>
  <li>The value of $str or @matchedPath sometimes blank when I print out. It is not random, it happen only to certain Path in the table.txt file, which I can't figure it out, why?</li>
  <li>How to print like the outcome, because I can't find the correct file location or directory of table.txt file because I have put all the path location in an array, filtered it and compared with the matched correct file location of table.txt, because of this, some location is missing when printed out.</li>
  </ol>
  
  <p>Example path that the /home/is/latest/table.txt files contain, the bold texts is the wanted path in table.txt,</p>
  
  <pre><code>##WHAT PATH IS_THAT,Backup
  a   b/c/d   B
  a   b/c/d/e  B
  a   b/c/d/e/f  B
  a   b/c/d/g  B
  </code></pre>
  
  <p>Example path that the /home/are/latest/table.txt files contain, the middle texts is the wanted path in table.txt,</p>
  
  <pre><code>##WHAT PATH IS_THAT,Backup
  a   b/c/d/j B
  </code></pre>
  
  <p>e.g. list.txt file contains,</p>
  
  <pre><code>rty/b
  uio/b/c
  qwe/b/c/d
  asd/b/c/d/e
  zxc/b/c/d/e/f
  vbn/c/d/e
  fgh/j/k/l
  </code></pre>
  
  <p>Expected outcome:</p>
  
  <pre><code>Unmatched Path         : b/c/d/g
  table.txt file location: /home/is/latest/table.txt
  
  Unmatched Path         : b/c/d/j
  table.txt file location: /home/are/latest/table.txt
  </code></pre>
  
  <p>Below is my detailed script,</p>
  
  <pre><code>#!/usr/perl/5.14.1/bin/perl 
  
  # I want to make a script that automatically compare the path in table.txt with list.txt
  #table.txt files is located under a parent directory and it differs in the subdirectory.
  #There is about 10 table.txt files and each one of it need to compare with list.txt
  #The objective is to print out the path that are not in the list.txt
  
  use strict;
  use warnings;
  use Switch;
  use Getopt::Std;
  use Getopt::Long;
  use Term::ANSIColor qw(:constants);
  use File::Find::Rule;
  use File::Find;
  use File::Copy;
  use Cwd;
  use Term::ANSIColor;
  
  my $path1='/home';                                                      #Automatically search all table.txt file in this directory even in subdirectory
  my $version='latest';                                                   #search the file specified subdirectory e.g. /home/is/latest/table.txt and /home/are/latest/table.txt
  my $path2='/list.text';                                                 #there is about 10 table.txt files which contain specified paths in it.
  
  $path1 =~ s/^\s+|\s+$//g;
  $version =~ s/^\s+|\s+$//g;
  $path2 =~ s/^\s+|\s+$//g;
  
  my @files = File::Find::Rule-&gt;file()
                              -&gt;name( 'table.txt' )
                              -&gt;in( "$path1" );
  
  my @symlink_dirs = File::Find::Rule-&gt;directory-&gt;symlink-&gt;in($path1);      #If the directory is a symlink, in my case 'latest' is a symlink directory
  print colored (sprintf ("\n\n\tSUMMARY REPORT"),'bold','magenta');
  print  "\n\n_______________________________________________________________________________________________________________________________________________________\n\n";
  
  if ($version eq "latest")
  {
      foreach my $dir (@symlink_dirs) 
      {
          my @filess = File::Find::Rule-&gt;file()
                                       -&gt;name( 'table.txt' )
                                       -&gt;in( "$path1" );
          my $symDir=($dir."/"."table.txt");
          $symDir =~ s/^\s+|\s+$//g;
          my $wantedPath=$symDir;
          my $path_1 = $wantedPath;
          function($path_1);      
  
      }
  }
  
  else 
  {
  
      for my $file (@files)   
      {
  
          if ($file =~ m/.*$version.*/)
          {
          my $wantedPath=$file;
              my $path_1 = $wantedPath;
              function($path_1);  
          }
      }
  }
  
  sub function
      {
  
      my $path_1 = $_[0];
      open DATA, '&lt;', $path_1 or die "Could not open $path_1: $!";
  
      my $path_2 = "$path2";
      open DATA1, '&lt;', $path_2 or die "Could not open $path_2: $!";
  
  ################# FOCUSED PROBLEM AREA ##############################       
      my @matchedPath;
      my @matched_File_Path;
      my @unmatchedPath;
      my @unmatched_File_Path;
      my @s2 = &lt;DATA1&gt;;
  
          while(&lt;DATA&gt;)
          {
  
          my $s1 = $_;
  
              if ($s1 =~ /^#.*/) 
              {
              next;
              }
  
              if ($s1 =~ /(.*)\s+(.*)\s+(.*)\s+/) 
              {
              my $str=($2);
              $str =~ s/\s+//g;
  
                  for my $s2 (@s2)
                  {
  
                      if ($s2 =~ /.*$str/)
                      {
                      push @matchedPath,$str;                                      
                      push @matched_File_Path,$path_1;                                
                      print "matched Path: $str\n\t$path_1\n"; #I don't understand, sometimes I get empty $str value in this. Can anyone help me?
                      last;
                      }
                      else
                      {
                      #print "unmatch:$str\n\t$path_1\n";                     
                      push @unmatchedPath,$str;                                   
                      @unmatched_File_Path,$path_1;
                                          }
                  }
              }
          }
          foreach (@unmatchedPath)
          {print "unmatch path: $_\n";}        
          foreach (@matchedPath)
          {print "\nmatch path: $_\n\n";}     
  
          foreach (@unmatched_File_Path)       
          {print "unmatch File Path: $_\n";}
          foreach (@matched_File_Path)         
          {print "match File Path: $_\n";}
  
          my @filteredUnmatchedPath = uniq(@unmatchedPath);                   
          my @filteredUnmatched_IP_File_Path =uniq(@unmatched_IP_File_Path); 
           @filteredUnmatchedPath = grep {my $filteredPath = $_; not grep $_ eq $filteredPath, @matchedPath} @filteredUnmatchedPath;
  }
          print "@filteredUnmatchedPath\n";   
          print "@filteredUnmatched_IP_File_Path\n";
  
  sub uniq 
  {
      my %seen;
      grep !$seen{$_}++, @_;
  }
  
  
  
  close(DATA);
  close(DATA1);
  
  print  "_________________________________________________________________________________________________________________________________________________________\n\n";
  </code></pre>