in reply to caller of perl script

I'm curious as to why you need this. This could be an XY Problem.

which is called by either a shell script or a bat file.

Batch files are scripts for the command or cmd shell, meaning they are shell scripts.