title: Using grep in if statements in perl
body: <p>I have multiple log files that looks like dmesg output. I need to parse and store certain result from all these files into one single output file. 
  Ex Input file1:</p>
  
  <pre><code> .....
   Started 1399343129
   KbPerSec  1222
   KiloBytes 9302938
   Status 83
   StorageUNit unitname
   Ended 1399473434
   .......
  </code></pre>
  
  <p>Output file:</p>
  
  <pre><code>  1399343129  1222  9302938 83 unitname 1399473434
    &lt;input file2 numbers&gt;
    &lt;input file3 numbers&gt;
    .....
  </code></pre>
  
  <p>So, I use grep, and split the grep result to get the number I want. Here is what my code looks like.
  <code>&lt;TRY&gt;</code> is my file handle. </p>
  
  <pre><code>my (@grepres, @splitres);
  my ($size, $start, $bw);
  
  if(@grepres=grep{/KbPerSec/} &lt;TRY&gt;){
    @splitres=split(' ',$grepres[0]);
    $bw=$splitres[1];
    print "1. $bw\n";
  }
  
  if(@grepres=grep{/Started/} &lt;TRY&gt;){
    @splitres=split(' ',$grepres[0]);
    $start=$splitres[1];
    print "$start\n";
  }
  
  ...
  </code></pre>
  
  <ol>
  <li>But my code only executes the first if, and then stops. Why does it not execute the other if statements?</li>
  <li>This doesnt seem like an efficient way to do this. How can I do better?</li>
  </ol>