#use strict; use warnings; sub subfunction { foreach my $j (0..5) { my $SUB = 'testsub'.$j; *$SUB = sub { display($j); }; } } sub display { my $x = shift; print "\$x = $x\n"; } subfunction(); &testsub0(); &testsub1(); &testsub2(); &testsub3(); &testsub4(); &testsub5(); __END__ $x = 0 $x = 1 $x = 2 $x = 3 $x = 4 $x = 5