BEGIN { sub my_use { my ($arg_ref, $module) = @_; my $version; local @INC; (undef, $version, @INC) = @$arg_ref; require File::Spec; for my $dir ( grep { -e File::Spec->catfile( $_, $module ) } @INC ) { my $file = File::Spec->catfile( $dir, $module ); open MOD, "<", $file or warn "failed opening $file : $@"; grep { /(?:VERSION\s*=(.*))/ and eval "eval '$1' || 0" == $version and do { open my $fh, "<", $file or warn "open $file failed : $@"; close MOD; return $fh; } } ; } } { local @INC = [ \&my_use, "1.03", qw|a b c|, @INC ]; eval "use strict"; } { local @INC = [ \&my_use, "5.01", @INC, qw|a b c|]; eval "use Foo::Bar"; } }