title: How can I print lines that match a pattern in Perl?
body: <p>Assuming <code>file.txt</code> has just one sentence per line  as follows:</p>
  
  <pre>John Depp is a great guy.  
  He is very inteligent.  
  He can do anything.  
  Come and meet John Depp.</pre>
  
  <p>The Perl code is as follows:-</p>
  
  <pre><code>open ( FILE, "file.txt" ) || die "can't open file!";
  @lines = &lt;FILE&gt;;
  close (FILE);
  $string = "John Depp";
  foreach $line (@lines) {
      if ($line =~ $string) { print "$line"; }
  }
  </code></pre>
  
  <p>The output is going to be first and fourth line.</p>
  
  <p>I want to make it working for  the file having random line breaks rather than one English sentence per line. I mean it should also work for the following:-</p>
  
  <pre>John Depp is a great guy. He is very intelligent. He can do anything. Come and meet John Depp.</pre>
  
  <p>The output should be first and fourth sentences.</p>
  
  <p>Any ideas please?</p>