title: How can I see if a Perl hash already has a certain key?
body: <p>I have a Perl script that is counting the number of occurrences of various strings in a text file. I want to be able to check if a certain string is not yet a key in the hash. Is there a better way of doing this altogether?</p>
  
  <p>Here is what I am doing:</p>
  
  <pre><code>foreach $line (@lines){
      if(($line =~ m|my regex|) )
      {
          $string = $1;
          if ($string is not a key in %strings) # "strings" is an associative array
          {
              $strings{$string} = 1;
          }
          else
          {
              $n = ($strings{$string});
              $strings{$string} = $n +1;
          }
      }
  }
  </code></pre>