my %package = qw( W pack_W X pack_X Y pack_Y Z pack_Z ); unless (exists $package{$state}) { # Handle this error somehow... die "State '$state' is not implemented"; } my $package_file = "$package{$state}.pm"; $package_file =~ s~::~/~g; require($package_file); my $app = $package{$state}->new(%stuff); $app->run;