title: Perl Substring extraction using regex: Split vs Substitution
body: <p>I have written the following snippets of code to split a properties string:</p>
  
  <h2>Input</h2>
  
  <pre><code>$line='VarBinds=var0\=DU_/data02;var1\=GE;var2\=95;var3\=LT;var4\=95;var5\=95';
  </code></pre>
  
  <h2>Code 1:</h2>
  
  <pre><code>my ($field,@v)=split /=/, $line;
  my $value=join '=', @v;
  </code></pre>
  
  <h2>Code 2:</h2>
  
  <pre><code>my $field=$line;
  my $value = $field;
  $field =~ s#^([[:alnum:]]+)=.*#$1#;
  $value =~ s#^[[:alnum:]]+=##;
  </code></pre>
  
  <p>Which is a better piece of code, and why? <a href="http://www.perlmonks.org/?node_id=591988" rel="nofollow">This article</a> on <code>perl monks</code> leads me to believe that <code>Code 1</code> is better than <code>Code 2</code>, but I am not sure.</p>
  
  <p>Please note that I've used the code below(which is better than both <code>Code 1</code> and <code>Code 2</code>).</p>
  
  <h2>My Code:</h2>
  
  <pre><code>my ($field,$value)=split /=/, $line, 2;
  </code></pre>
  
  <p>Any improvement to <code>My Code</code> are also welcome.</p>
  
  <h2>EDIT:</h2>
  
  <ul>
  <li>Clarified the question a bit.</li>
  </ul>