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 { unless ($evalled++) { # we haven't evalled the rest before $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 #### use Foo 'usebytes'; # or something else to not use bytes my $foo = Foo->new;