... my %hash; while () { my $name = ... my $code = ... push @{ $hash{$name} }, $code; }