I don't know why you check if C:\Oracle\Ora12c\perl\bin exists in non standard environment variable machine to determine if %oracle_home%\perl\bin should be added to system environment variable PATH. I suggest to check system PATH for existence of this directory path.
EOF is no valid command. Therefore the Windows command processor outputs an error message and continues with next command line being the line with setx. This is the reason why your batch code does not work. The command in ELSE branch should be goto :EOF.
Much better would be following code which checks if %oracle_home%\perl\bin or its expanded equivalent exists in system PATH and appends instead of prepends it to system PATH if not existing in system PATH.
@echo off
if not exist "%oracle_home%\perl\bin\*" goto :EOF
setlocal EnableExtensions DisableDelayedExpansion
for /F "skip=2 tokens=1,2*" %%N in ('%SystemRoot%\System32\reg.exe query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v "Path" 2^>nul') do (
if /I "%%N" == "Path" (
set "SystemPath=%%P"
if defined SystemPath goto CheckPath
)
)
echo Error: System environment variable PATH not found with a non-empty value.
echo/
endlocal
pause
goto :EOF
:CheckPath
setlocal EnableDelayedExpansion
set "Separator="
set "PathToAdd=%%oracle_home%%\perl\bin"
set "OraclePerlPath=%oracle_home%\perl\bin"
if not "!SystemPath:~-1!" == ";" set "Separator=;"
if "!SystemPath:%PathToAdd%=!" == "!SystemPath!" (
if "!SystemPath:%OraclePerlPath%=!" == "!SystemPath!" (
set "PathToSet=!SystemPath!%Separator%!PathToAdd!"
set "UseSetx=1"
if not "!PathToSet:~1024,1!" == "" set "UseSetx="
if not exist %SystemRoot%\System32\setx.exe set "UseSetx="
if defined UseSetx (
%SystemRoot%\System32\setx.exe Path "!PathToSet!" /M >nul
) else (
set "ValueType=REG_EXPAND_SZ"
if "!PathToSet:%%=!" == "!PathToSet!" set "ValueType=REG_SZ"
%SystemRoot%\System32\reg.exe ADD "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /f /v Path /t !ValueType! /d "!PathToSet!" >nul
)
)
)
endlocal
endlocal
For details on this batch code read answer on Why are other folder paths also added to system PATH with SetX and not only the specified folder path? used as template for this batch code. It explains also why batch code in question is definitely not good at all.
Note 1: Command setx is by default not available on Windows XP.
Note 2: Command setx truncates values longer than 1024 characters to 1024 characters.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
goto /?
if /?
pause /?
reg /? and reg add /? and reg query /?
set /?
setlocal /?
setx /?