http://www.perlmonks.org?node_id=226782


in reply to How to use dynamic execution path instead of absolut.

On Unix system the following should work:
#!/bin/sh `which perl` -x $0 $* exit #!perl print "hello perl\n";
which finds (hopefully) your perl.
The backticks execute the found perl.
The -x switch forces perl to skip everything before #!perl
$0 is the scriptname.
$* are all commandline parameters.