my %dispatch = ( From => sub { return '"Nobody" '; }, Subject => sub { die "The GNKSA requires that the subject field always be specified by the user."; }, # and so forth. ); #### for my $k (keys %dispatch) { if (exists $config{$k}) { $value{$k} = $config{$k}; } else { $value{$k} = $dispatch{$k}->(); } }