title: PERL: how to search/replace elegantly beyond carriage return?
body: <p>I had trouble googling this, as most people seem to want to know how to remove a carriage return.</p>
  
  <p>The code I have works, but it seems awkward, and I'm missing something. It may be that my original script is designed poorly (I'm checking if one element occurs last, and if so, I need to change it,) but still...it seems I'm missing a quick way to make things smoother.</p>
  
  <pre><code>use strict;
  use warnings;
  
  my $a = "This is a string that I concatenate beforehand with carriage returns, so it's hard to separate out.\nThis is the last line I want to track.\nI want to delete this line.";
  my $b = $a;
  
  $b =~ s/(track\.).*/$1/g;
  
  print "THIRD LINE STILL THERE\n$b\n\n";
  
  my @c = split(/\n/, $a);
  for (0..$#c) { 
     if ($c[$_] =~ /last line/) { 
        $b = join("\n", @c[0..$_]); 
        last; 
     } 
  }
  
  print "THIRD LINE GONE. IT WORKS, BUT I THINK THERE MUST BE A BETTER WAY.\n$b\n";
  </code></pre>