Whilst it appears that #! does not need to be read by Perl (but by the Unixesque Operating system), Windows has no inbuilt understanding of the #!. Instead, Windows Perl interpreters (such as ActiveState Perl) will, when running a perl program with a #! line read it and run as if those commands were given on the command line. For example:

#!d:\perl\bin\perl -w

will run Perl with the use warnings pragma, telling Perl to throw a wobbly at any slightly wrong statements.

The interesting thing is that it ignores the pathname since it is already running under perl, so using:

#!/usr/bin/perl -w

gives exactly the same effects, as well as incorporating Unix compatibility.

It should be remembered, however, that Apache Web Server does parse #!'s on Windows machines in the usual way, so #!/usr/bin/perl -w won't work: you'll need the correct path.


With thanks to ariels, who pointed out that Perl always checks the parameters at the end of a shebang line... for 'various arcane reasons', and rp who pointed out it's Linux, not Bash which does the work.