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 has
Well, your whole code can be limited to:
foreach $line (@lines){ $strings{$1}++ if $line =~ m|my regex|; }
If the value is not there, ++ operator will assume it to be 0 (and then increment to 1). If it is already there - it will simply be incremented.