sub main { print "Hello, world!\n"; } unless (caller) { main; } #### #!/usr/bin/perl # File: demo.pl use strict; use warnings; $|=1; # turn off buffering use Demo qw(example); # test() is not exported by Demo.pl # this the error produced... # Undefined subroutine &main::test called at C:\Projects_Perl\testing\demo.pl line 7. # my $x = test(); my $y = Demo::test(); #this is ok , Fully qualified name print "test() returned $y\n"; __END__ Prints: top level in Demo.pm this is the test subroutine! test() returned 1 #### #!/usr/bin/perl # File: Demo.pm use strict; use warnings; package Demo; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; our $VERSION=1.01; our @ISA = qw(Exporter); our @EXPORT = qw(); our @EXPORT_OK = qw(example); our $DEBUG =0; test() if !caller; # runs test() if run as a "main program" sub test { print "this is the test subroutine!\n"; return 1;} sub example {return "this is an example"}; print "top level in Demo.pm\n"; 1;