# the code is loaded into $code from a DB in my case # and it loops around the sub below to load all plugins. # In your file you would have an anonymous sub routine # like { my $times=shift; for (1...$times) { print "Hello, World!\n"; } } # check reference type my $eval_code = sub { $code }; my $chk_ref=ref $eval_code; if ($chk_ref !~ /CODE/) { print "[load_plugins] Error loading plugin $name: Not CODE!\n"; } else { # test code $eval_code = eval "sub { $code }"; } if ($@) { chomp($@); print "[load_plugins] Error loading plugin $name: $@\n"; } else { # store code in a hash $code{$name} = ( { id => $id, name => $name, code => $eval_code, }, ); print "[load_plugins] Plugin $name loaded successfully.\n"; }