@echo off echo Hello from the DOS/Windows command interpreter perl -x -S %0 goto batchend #!perl use strict; use warnings; print "Hello from Perl\n"; exit; __END__ :batchend echo Back from perl in the command interpreter #### rem -- somewhere inside the big batch file -- perl -e "exit 42" if errorlevel 43 goto noperl if errorlevel 42 goto badperl goto noperl :badperl echo Sorry, there is a foreign perl installed. Can't install. goto fail :noperl rem ... rem ... much code omitted, explained in the next step rem ... :fail pause :end #### rem ... rem (assuming this script is named setup.bat) if exists setup.bat goto havesetup echo Can't find myself. Can't install. goto fail :havesetup rem (assuming our perl.exe is in a bin subdirectory) if not exists perl.exe goto dirsok echo ZIP file was unpacked without directories. Can't install. goto fail :dirsok if exists bin\perl.exe goto haveperl echo Missing my perl.exe. Archive damaged? Can't install. goto fail :haveperl rem ... rem ... use perl to bootstrap itself rem ... :fail pause :end #### rem ... bin\perl.exe -e "exit($]!=5.014002)" if not errorlevel 1 goto perlok echo Unexpected perl interpreter found. Won't install. goto fail :perlok rem ... :fail pause :end #### rem ... perl -x -S %0 if errorlevel 1 goto fail goto end rem -- command shell will never try to interpret this or the following lines up to the fail label. #!perl use strict; use warnings; use lib 'lib'; use My::Custom::Setup; My::Custom::Setup->run(); __END__ rem ^-- perl stops interpreting at __END__ :fail pause end #### #!perl use strict; use warnings; if (eval q[ use lib 'lib'; use My::Custom::Setup; My::Custom::Setup->run(); 1; ]) { exit(0); } else { my $err=$@; Win32::MsgBox($err,MB_ICONSTOP,"Error"); die $err; } __END__