if ($ENV{'-'} =~ 'i') { # interactive invocation } else { # non-interactive e.g. cron, invocation }