Environment Variables

In addition to the various switches that explicitly modify Perl’s behavior, you can set various environment variables to influence various underlying behaviors. How you set up these environment variables is system dependent, but one trick you should know if you use sh, ksh, or bash is that you can temporarily set an environment variable for a single command, as if it were a funny kind of switch. It has to be set in front of the command:

$ PATH='/bin:/usr/bin' perl myproggie

You can do something similar with a subshell in csh and tcsh:

% (setenv PATH "/bin:/usr/bin"; perl myproggie)

Otherwise, you’d typically set environment variables in some file with a name resembling .cshrc or .profile in your home directory. Under csh and tcsh you’d say:

% setenv PATH '/bin:/usr/bin'

And under sh, ksh, and bash you’d say:

$ PATH='/bin:/usr/bin'; export PATH

Other systems will have other ways of setting these on a semipermanent basis. Here are the environment variables Perl pays attention to:


Used if chdir is called without an argument.


Environment variables that control how Perl handles data specific to particular natural languages. See the online docs for perllocale.


Used if chdir has no argument but HOME is not set.


Used in executing subprocesses and for finding the program if the –S switch is used.


The command used to load the debugger code. The default is:

BEGIN { require "perl5db.pl" }

See Chapter 18 for more ...

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.