package MyText; sub init_XS { my $class = shift; my $usexs = shift; if ($usexs) { eval { use Text::CSV_XS; @ISA = ('Text::CSV_XS'); } } else { eval { use Text::CSV; @ISA = ('Text::CSV'); } } } 1; #### use MyText; my $usexs = 1; #decide whether to use XS MyText->init_XS($usexs); my $csvobj = MyText->new(); #Text::CSV_XS->new gets called if $usexs is true. #Text::CSV->new gets called if $usexs is false. #do stuff with $csvobj