title: Append a string in the beginning of a line when regex matches
body: <p>I have a file for example</p>
  
  <pre><code>Car   class    rating
  ford    c        ok
  merc    a        Vgood
  BMW     a        Toogood
  kia     c         ok
  </code></pre>
  
  <p>I want to append 'prefer' and 'dontprefer' at the beginning of the line when "a" and "c" are found respectively.</p>
  
  <p>I have been doing this by seperating lines with "a" and "c" into different files and then append the required.</p>
  
  <pre><code>perl -ne '/a/ &amp;&amp; print' file1.l &gt; file2.l 
  
  perl -ple 's/^/prefer/' file2.l
  </code></pre>
  
  <p>I have been doing this for each regex match and then combine all the files once appeneded.</p>
  
  <p>So it there any other simple code to append the strings in the same file instead of shanging the files each time a regex is matched?</p>
  
  <p>Sample output:</p>
  
  <pre><code>  .  .          Car   class    rating
  
  dontprefer    ford    c        ok
  prefer        merc    a        Vgood
  prefer        BMW     a        Toogood
  dontprefer    kia     c         ok
  </code></pre>