sub make_sub_for_given_key { my( $key ) = @_; # amongst other arguments return sub { # this sub "knows" what $key is, forever. print "Hi! I belong to key '$key'\n"; } } my $key = "Tuesday"; my %hash; $hash{ $key } = make_sub_for_given_key( $key ); # later on, ask each sub what key it belongs to: for $key ( keys %hash ) { $hash{$key}->(); }