in reply to Need some data structures cooked

I don't get why you care about $iteration. You use it to accumulate counts, pull the counts out of it to add them to {'stack'}, then never throw it away. Looks like a memory leak to me.

You could simplify your data structures by using separate hashes for per-iteration and accumulated data. Then you would write

$vips{$2}++; ... push @{$vipstack{$k}}, $vips{$k}; shift @{$vipstack{$k}} if @{$vipstack{$k}} > 50; ... my $temp = $vipstack{$k};
Oh, and

#5. You aren't using strict.