Perl shebang for different versions

In a Perl script typically a shebang line is something like:


this works great if you want to use a wide, system based, Perl for your scripts. But what if you have several different installations of Perl and want to run the same script using different Perl versions without having to change the shebang line. Well, one possible and straightforward solution is to change it to something like:

#!/usr/bin/env perl

and then push the version you want to use to your $PATH environment variable. This can even be easily done based on the user. For example, you can have a user named 'perl_5.10' and for that user have:


now, this user runs scripts (with the env version of the shebang line) using Perl 5.10.


Unless you have a CGI running under Apache. Then your shebang must be:


Yeah, not using /usr/bin/env for perl, python, sh etc. is one of my biggest pet peeves about Unix programs.

Using a "wide" Perl should be discouraged! :-p

If you're going to put perl_5.10/bin first in your $PATH anyway, what difference does env make?

$PATH isn't used for absolute paths, i.e. this:


Always uses /usr/bin/perl regardless of your $PATH settings. These two are different however:

#!/usr/bin/env perl

Leave a comment

About smash

user-pic I blog about Perl.