my %genes_number =(); while(){ chomp; my @current_line = split /\t/; #%gc_ag hash has sotred the keys and values # read from another file. Keys are 5 to 18 # and values are some numbers for each #key explained in read more foreach my $k (sort {$a<=>$b} keys %gc_ag) { if ($current_line[3] == $k && $current_line[8] > $gc_ag{$k} ) { # push(@genes_number, $current_line[1]); # this was my original array that was used in # in the sub. Now the sub needs to be changed # according to the following array of hash push(@{$genes_number{$k}}, $current_line[1]); } } } #################################### ###########subroutine############### sub count_unique { @genes_number = @_; my %count; map { $count{$_}++ } @genes_number; #print them out: map {push our @arr, ${count{$_}}} sort keys(%count); for (my $j=1; $j<10; $j++){ my $counter =0; foreach my $element(@arr) { if ($element >=$j) { $counter++; } } print "$j\t$counter\n"; } my $i =0; $i += keys %count; # print $i; return %count; }