#!/usr/bin/perl use warnings; use strict; # Altvernative mit eval # ~~~~~~~~~~~~~~~~~~~~~ my $key = 1; my %switch = ( 1 => "f1('Hallo')",                2 => "f2",                3 => "f3", ); print eval $switch{$key}; sub f1 {   shift, "\n"; } sub f2 {   print "f2\n";   return; } sub f3 {   print "f3\n";   return; } # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 1. Alternative ohne eval # ~~~~~~~~~~~~~~~~~~~~~~~~ %switch = ( 1 => x1(1,3),             2 => x2(2,3),             3 => x3(3,3) ); my $key1 = 1; print $switch{$key1}."\n"; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # 2. Alternative ohne eval # ~~~~~~~~~~~~~~~~~~~~~~~~ my $key2 = 2; SWITCH:{   if ($key2 == 1) { print x1($key2,10), "\n"; last SWITCH;}   if ($key2 == 2) { print x2($key2,10), "\n"; last SWITCH;}   if ($key2 == 3) { print x3($key2,10), "\n"; last SWITCH;} } sub x1 {   $_[0] * $_[1]; } sub x2 {   $_[0] * $_[1]; } sub x3 {   $_[0] * $_[1]; }