I doubt that you can force windows to accept shbang ( #!). Therefore, if you can work with the default shell (in my case bash), then this works in bash:
@REM <<:END_REM
@echo off
echo This is DOS, this will only run in DOS.
perl -x -S %0 %*
goto over_nix
:END_REM
echo This is *NIX, this will only run in *NIX.
perl -x -S $0 $*
:<<__END__
#!perl
use 5.012;
use Data::Dumper;
say Dumper( \%ENV );
__END__
@REM <<:over_nix
:over_nix
This required an executable file in my NIX path named '@REM'.
echo >> ~/bin/@REM
chmod +x ~/bin/@REM
source
share