my @tags= qw/name gender address/; foreach my $t (@tags) { eval "sub $t { \$state{'$name'} = 1; }"; eval "sub ${t}_ { \$state{'$name'} = 1; }"; } #### BEGIN { unless(-e "Tags.pm") { my @tags= qw/name gender address/; open( F, ">Tags.pm" ) or die "Unable to create Tags.pm:$!"; foreach my $t (@tags) { print F "sub $t { \$state{'$name'} = 1; }\n"; print F "sub ${t}_ { \$state{'$name'} = 1; }\n"; } print F "1;\n"; close( F ) or die "Unable to close Tags.pm:$!"; } } use Tags;