The issue is that Git for Windows comes with its own perl, as do other systems like MSYS2. If these are all in the path the simplest(?) solution is to ensure the one you want to use is pushed to the front of the path when it is needed.
In the case of Strawberry perl, the portable version comes with a script to do so, and this would appear to be the original source of the OP's script (or share a common source). See https://github.com/StrawberryPerl/Perl-Dist-Strawberry/blob/master/share/portable/portableshell.bat.