in reply to find out the way program was called.

if ($0 eq __FILE__) { print "Called directly\n"; } else { print "Loaded in a library\n"; }