I'm not sure if this is what
chromatic suggested, but either one of these should do what you're looking for:
unless ( defined caller ) {
#code here
}
or
sub do_me {
#code to run here
}
do_me unless defined caller;
sub do_me or the block after
unless won't be executed when used or required, but will be executed from the command line.
From perldoc caller:
Returns the context of the current subroutine call. In scalar context, returns the caller's package name if there is a caller, that is, if we're in a subroutine or eval or require, and the undefined value otherwise.