#!/usr/bin/perl # In order to 'use' a perlmodule in a userspace library you need to add it to @INC. # But if you do not want to use an absolute path inside the script, you need this workaround: BEGIN{ use Cwd 'abs_path'; my $this = $0; # this script $this =~ s/[^\/]+$//; # strip the filename, now we have a (relative) directory my $path = abs_path($this); # now we have an absolute directory unshift @INC, $path; # which we add to @INC # chdir('/tmp'); # does seem to confuse abs_path! Uncomment to see } use My::Module; My::Module::print_file_name(); My::Module::print_script_name(); My::Module::print_caller_name();