#!/usr/bin/perl use strict; use warnings; use 5.010.000; use File::Basename qw( basename ); my @dispatchtab = ( { moduldatei => 'test_extern.pl', aufruf_sub => \&testsub, aufruf_neu => 'testsub', unit => 'unit1', }, { moduldatei => 'test_extern2.pl', aufruf_sub => \&testsub, aufruf_neu => 'testsub', unit => 'unit2', }, # hier sind natürlich noch ganz viele ); for my $ref ( @dispatchtab ) { # clean up file name for usage as namespace name (remove file path and extension and convert '-' to '_') ( my $namespace = basename( $ref->{moduldatei}, '.pl' ) ) =~ tr/-/_/; eval <<"EVAL_CODE"; package $namespace; # declare package to contain imported functions require "$ref->{moduldatei}"; # "import" function(s) $ref->{aufruf_sub}('a'); # call function with string-eval; remember to insert error handling # We are inside package MyModule, so no need for package name in string EVAL_CODE warn "$@\n" if $@; }