use UNIVERSAL::require; my $fetcher_class = choose_fetcher_class(); my $fetcher = $fetcher_class->new; # this is the good part # this line of code does not care what driver it's using, as # long as the subclass of MyApp::URLFetcher is implemented correctly # isn't polymorphism great? my $content = $fetcher->get($url); sub choose_fetcher_class { foreach my $driver (qw/LWP NetFTP/){ my $class = "MyApp::URLFetcher::$driver"; # UNIVERSAL::require let's us avoid an eval return $class if $class->require; } die "couldn't load any driver"; }