title: perl reading file and grabbing specific lines
body: <p>I have a text file and I want to grab specific lines starting with a pattern and ending with a specific pattern.
  Example:</p>
  
  <pre><code>Text
  Text
  Startpattern
  print this line
  Print this line
  print this line
  Endpattern
  Text
  Text
  Text
  </code></pre>
  
  <p>Also the start pattern and the end pattern should be printed. My first try was not really successful:</p>
  
  <pre><code>
  my $LOGFILE = "/var/log/logfile";
  my @array;
  # open the file (or die trying)
  
  open(LOGFILE) or die("Could not open log file.");
  foreach $line () {
    if($line =~  m/Sstartpattern/i){
      print $line;
      foreach $line2 () {
        if(!$line =~  m/Endpattern/i){
          print $line2;
        }
      }
    }
  }
  close(LOGFILE);
  </code></pre>
  
  <p>Thanks in advance for your help.</p>