title: Perl, Assign to variable from regex match
body: <p>I am relatively new to perl and there is an example snippet of code in <a href="http://exchange.nagios.org/directory/Plugins/Hardware/Server-Hardware/HP-%28Compaq%29/check_ilo2_health/details">check_ilo2_health.pl</a> in which there is a piece of syntax that I do not understand how or why it works. The code snippet is parsing SSL client data, in this case XML, line by line.</p>
  
  <pre><code>if ( $line =~ m/MESSAGE='/) {
     my ($msg) = ( $line =~ m/MESSAGE='(.*)'/);  #&lt;---- HERE
  
     if ( $msg !~ m/No error/ ) {
        if ( $msg =~ m/Syntax error/ ) {  #...etc
  </code></pre>
  
  <p>An example of the XML in question:</p>
  
  <pre><code>&lt;RESPONSE
      STATUS="0x0000"
      MESSAGE='No error'
   /&gt;
  </code></pre>
  
  <p>So in this case the <em>if</em> statement takes the <em>MESSAGE</em> line of the XML sample. I understand that <em>my ($msg)</em> treats the variable as a sort of list and I understand how the regular expressions match; however, what I do not understand is the syntax such that <em>$msg</em> is <strong>assigned</strong> to <em>No error</em>. The perl seems to be playing around with parenthesis syntax and such for this to work. While it works I would like to know how it works. Any assistance would be appreciated.</p>