title: Find all the occurrence of string in a file and print its line number in Perl
body: <p>I have a large file which contains 400000 lines, each line contains many number of keywords separated by tab.</p>
  
  <p>And also I have a file that contains list of keywords to be matched. Say this file act as a look up.</p>
  
  <p>So for each keyword in the look up table I need to search all its occurrence in the given file. And should print the line number of the occurrence.</p>
  
  <p>I have tried this </p>
  
  <pre><code>#!usr/bin/perl
  use strict;
  use warnings;
  
  my $linenum = 0;
  
  print "Enter the file path of lookup table:";
  my $filepath1 = &lt;&gt;;
  
  print "Enter the file path that contains keywords :";
  my $filepath2 = &lt;&gt;;
  
  open( FILE1, "&lt; $filepath1" );
  open FILE2, "&lt; $filepath2" ;
  
  open OUT, "&gt;", "SampleLineNum.txt";
  
  while( $line = &lt;FILE1&gt; )
  {
      while( &lt;FILE2&gt; ) 
      {
          $linenum = $., last if(/$line/);
      }
      print OUT "$linenum ";
  }
  
  close FILE1;
  </code></pre>
  
  <p>This gives the first occurrence of the keyword. But I need all the occurrence and also the keyword should be exactly match.</p>
  
  <p>The problem am facing in exact match is, for instance I have the keywords "hello" and "hello world"</p>
  
  <p>if I need to match "hello", it returns the line number which contains "hello world" also
  my script should match only "hello" and give its line number.</p>