:Loop REM If there are no parameters left, just go run perl if !%1! == !! goto doit REM If there's a -L, set the log flag if !%1! == !-L! set log=1 REM If this isn't a -L, push it on to the params stack if not !%1! == !-L! set params=%params% %1 REM Shift that %1 off and continue (%2 is now %1, etc) shift goto Loop :doit if !%log%! == !1! goto Log c:\devt\perl\bin\perl.exe %params% goto ciao :Log c:\devt\perl\bin\perl.exe %params% > stdout.log :ciao set params= set log= echo on