in reply to Match Count

de2425, this is a fast and dirty rewrite of your code, incorporating some of moritz's and shmem's comments. Further, I'll note you don't get keys from $ING, but rather from the hash %ING. The code below has not been run but it has been checked for syntax with perl -cw. I'll note that most of what I've done is clean up the variable syntax (and I'm sure someone else could do a better job of it).
I've also taken the time to eliminate a lot of those hard coded files and directory settings. The name of the output file can now be passed as a parameter as well.

#!/usr/bin/perl use warnings; use strict; # # Rewrite for legibility. # This code is not tested. # my $output_file = shift || "Cytokine.txt"; my $work_dir = "c:/work/Cytokine_By_Company"; my $report_dir = "c:/work/GeneID_Count"; my $data_set_one = "ING_cytokines_200805.txt"; my $data_set_two = "CytokineArrays.txt"; my %ING; open (IN, "< $work_dir/$data_set_one") or die "Could not open input file $data_set_one. $!\n"; while (<IN>) { chomp; my @source_data = split(/\t/,$_); $ING{$source_data[8]}{name} = $source_data[0]; $ING{$source_data[8]}{count} = 0; } close IN; open (OUT, "> $report_dir/$output_file") or die "Could not open file $output_file. $!\n"; open (IN, "< $work_dir/$data_set_two") or die "Could not open file $data_set_two. $!\n"; while(<IN>) { chomp; my @target_data = split(/\t/,$_); my $cytokine_id = $target_data[2]; while (/\d+/ and exists $ING{$cytokine_id}{name}) { $ING{$cytokine_id}{count}++; } for my $id ( sort{ $ING{$b} <=> $ING{$a} } keys %ING) { print OUT "$ING{$id}{name}\t$ING{$id}{count}\n"; } } close IN; close OUT;