in reply to set env var at compile time

I have no idea if this actually works, but you could try this:
BEGIN { unless($ENV{LD_LIBRARY_PATH}){ $ENV{LD_LIBRARY_PATH} = "whatever"; exec $^X, $0, @ARGV; } }

This re-executes the current script after setting the environment variable, in the hope that it works then in the same way as it does when you provide it through external environment variables.

(No idea if this makes a difference at. But there's no harm in trying).