use v5.24; use warnings; my %hash = ( do { my $key = 'AAA'; $key, sub { say $key; }; }, do { my $key = 'BBB'; $key, sub { say $key; }; }, ); $hash{'AAA'}->(); $hash{'BBB'}->();