use strict; use warnings; my $num = 1; my $mainObj = bless {}; my $handler = $mainObj->can("sub$num"); die "No handler for $num\n" if !defined $handler; $handler->(); sub sub1 { print "Handling case 1\n"; }