title: How can I do a conditional substitution in Perl?
body: <p>I am trying to convert as following:</p>
  
  <pre><code>bool foo(int a, unsigned short b)
  {
      return pImpl-&gt;foo(int a, unsigned short b);
  }
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>bool foo(int a, unsigned short b)
  {
      return pImpl-&gt;foo(a, b);
  }
  </code></pre>
  
  <p>In other words, I need to remove the type definition on the lines which are not the function definition.</p>
  
  <p>I am using Linux.</p>
  
  <p>The following removes the type on both lines:</p>
  
  <pre><code>perl -p -e 's/(?&lt;=[,(])\s*?(\w+ )*.*?(\w*)(?=[,)])/ $2/g;' fileName.cpp
  </code></pre>
  
  <p>How can I replace only on the line beginning with 'return' and still make multiple changes on the same line?</p>