title: Perl - substring keywords
body: <p>I have a text file where is lot of lines, I need search in this file keywords and if exist write to log file line where is keywords and line one line below and one above the keyword. Now search or write keyword not function if find write all and I dont known how can I write line below and above. Thanks for some advice.</p>
  <pre><code>my $vstup = &quot;C:/Users/Omega/Documents/Kontroly/testkontroly/kontroly20220513_154743.txt&quot;;
  my $log = &quot;C:/Users/Omega/Documents/Kontroly/testkontroly/kontroly.log&quot;;
      
  open( my $default_fh, &quot;&lt;&quot;, $vstup ) or die $!;
  open( my $main_fh,    &quot;&gt;&quot;, $log )    or die $!;
  
  my $var = 0;
  while ( &lt;$default_fh&gt; ) { 
      if (/\Volat\b/)
          $var = 1;
      }
      if ( $var )
          print $main_fh $_;
      }
  }
  
  close $default_fh;
  close $main_fh;
  </code></pre>