title: Compare two files with English and Japanese data
body: <p>I am asked to compare two files which contain some Japanese and English informaion. I use a slow approach, read two files and put them in two arrays, then use while loop to check whether the File_B's TERMS are WITHIN the lines of File_A.</p>
  
  <p>File_A:</p>
  
  <p>This is a boy.</p>
  
  <p>ハンカ</p>
  
  <p>She is a girl.</p>
  
  <p>I am a man.</p>
  
  <p>This apple is big.</p>
  
  <p>That orange is small.</p>
  
  <p>File_B:</p>
  
  <p>is a</p>
  
  <p>ハンカ</p>
  
  <p>small</p>
  
  <p>Output:</p>
  
  <p>I am a man.</p>
  
  <p>This apple is big.</p>
  
  <p>The program I wrote works fine. However, the files I am processing are very huge. The running time is so slow if I use looping like this. My friend told me that I can put the files into hash and it will run far much quicker. I can see the point of using it but the files I have are random and also the terms in File_B can be in any part of File_A. Some previous posts suggest that I can use split the lines of File_A, put the line in hash and compare it with File_B (put File_B in the other hash as well). However, I do not know how to do it besides using ~// to check whether the line got the term.</p>
  
  <pre><code>open(A_FILE, "&lt;", "FILE_A.txt");
  my(@a_lines) = &lt;A_FILE&gt;; # read file into list
  close(A_FILE);
  open(B_FILE, "&lt;", "FILE_B.txt");
  my(@b_lines) = &lt;B_FILE&gt;; # read file into list
  my($b_lines);
  close(B_FILE);
  open(my $out, "&gt;",  "Useful.txt") or die "Can't open Useful.txt: $!";
  $number = @b_lines;
  
  foreach $a_line (@a_lines) # loop thru list
  {
     $found = 0;
     my $sentence = $a_line;
     $i = 0;
     chomp($sentence);
     while (($i &lt;= $number-1) and ($found == 0)){
         chomp($b_lines[$i]);
         if ($sentence =~ /$b_lines[$i]/){
             $found = 1;
         }
         $i++;
     }
  
     if ($found == 1) {
         print $out $sentence."\n";
     }
  }
  </code></pre>