This will find perl on your PATH and you can add whatever other switches you'd like to the command line. You can even set environment variables, etc. before perl is invoked. The general idea is that sh runs the eval, but perl doesn't, and the extra gnarly bits ensure that Perl finds your program correctly and passes along all the arguments.

If you save the file with a .pl extension, your editor should detect the correct file syntax, but the initial shebang might throw it off. The other caveat is that if the Perl part of the script throws an error, the line number(s) might be off.

The neat thing about this trick is that it works for Ruby too (and possibly some other languages like Python, with additional modifications):

First, the shebang line is handled differently depending on the OS. I'm talking about GNU/Linux here, the leading operating system. ;)

The shebang line will be split only in two parts, the interpreter (usr/bin/perl) and the second argument which is supposed to prepend be the filename argument which itself will be append automatically when executing the shebanged file. Some interpreters need that. Like #!/usr/bin/awk -f for example. -f is needed in front of the filename argument.

Perl doesn't need the -f to pass the perl file name, meaning it works like

perl file.pl

instead of

perl -f file.pl

That gives you basically room for one argument switch that you can choose, like

#!/usr/bin/perl -w

to enable warnings. Furthermore, since perl is using getopt() to parse the command line arguments, and getopt() does not require argument switches to be separated by spaces, you pass even multiple switches as long as you don't separate them, like this:

#!/usr/bin/perl -Xw

Well, as soon as an option takes a value, like -a foo that doesn't work any more and such options can't be passed at all. No chance.

A more flexible way is to use a shell wrappper like this:

#!/bin/bash
exec perl -a -b=123 ... filename.pl

PS: Looking at your question again, you have been asking how to use perl switches together with /usr/bin/env perl. No chance. If you pass an option to Perl, like /usr/bin/env perl -w, Linux would try to open the interpreter 'perl -w'. No further splitting.