use Foo qw(usebytes); #### use Foo; #### package Foo; require bytes; # make sure the module is loaded without (un)import $bytes = 0; # flag: whether bytes should be enforced $evalled = 0; # flag: whether rest of source has been compiled sub import { if ($evalled++) { # we have evalled the rest before die qq{Can only have one setting of "use bytes" per run of Perl\n} if $bytes != ($_[1] eq "usebytes"); # different setting from before } else { # first time around $bytes = ($_[1] eq "usebytes"); # should bytes be enforced? local $/; # enable slurp mode eval ; # compile rest of source (after __DATA__) die $@ if $@; # die now if an error occurred } }; 1; # in order for require of Foo.pm to be successful __DATA__ # actual source of module starts here BEGIN {bytes->import if $bytes} # activate bytes if flag set sub new { bless {},shift } # example routine