use strict; use warnings; use 5.018; my %dispatch = ( lach => \&Booh::laugh, foo => \&main::bar, bar => \&baz, yipp =>\&jjj::YYY, ); require "jjj.pl"; package Booh; sub laugh { my $lach = shift // 'hahahahahahah'; say $lach; } 1; package main; sub bar { my $knete = shift // 'is nich'; say "Bar $knete aus der Kasse"; } sub baz { say 'Bar und Baaaatz'; } ########## my $coderef = Booh->can('laugh'); $coderef->('hihia'); # Boo::laugh(....) $dispatch{lach}->('Gacker!!!!!!!!!!!!!!!'); # auch Boo::laugh(....) $coderef = main->can('bar'); $coderef->(); $coderef->('100 EURO'); $coderef = jjj->can('YYY'); $coderef->(); $coderef->('Yippi'); $dispatch{'yipp'}->('hollaaaaaa'); 1;