foreach $key (%count){ if ($key =~ /CHECK/){ $c = $count{$key}; } else { $c1 = $count{$key}; } } print "c = c$ , c1 = $c1\n"