my @types = qw( date integer text timestamp ); foreach my $type (@types) { my $function = uc $type; no strict 'refs'; *$function = sub { if ( looks_like_number( $_[0] ) ) { die "Datatype '$type' does not require a numeric length '$_[0]'"; } return { type => $type, @_ }; }; }