http://www.perlmonks.org?node_id=920804

I'm running into some of the same problems outlined in PATH is not setting - PERL and DBI, DBD::Oracle and LD_LIBRARY_PATH (problem summary: LD_LIBRARY_PATH and sometimes other environment variables need to be set/unset to certain values before the program starts in order to run correctly), so here is my solution to it. Comments welcome...
package FixInit; sub import { return if $ENV{FIXINIT_PM}; my $class = shift; my @chk = $^C ? '-c' : (); $ENV{FIXINIT_PM} = 1; my @path; while ( my $dir = shift @_ ) { last if $dir eq "--"; push @path, $dir; } $ENV{LD_LIBRARY_PATH} = join ":", @path; my %env = @_; $ENV{keys %env} = values %env; exec $^X => @chk, $0, @ARGV; die "Could not exec $^X $0: $!"; } 1; __END__ =head1 NAME FixInit - Fix library path and ENV variables and restart program =head1 SYNOPSIS # Before all other use statements use FixInit; # or use FixInit qw(libpath1 libpath2 -- env1 value1 env2 value2); =head1 DESCRIPTION LD_LIBRARY_PATH interferes with the path used when some libraries were compiled. It should only be used as a last resort. Setting LD_LIBRARY_PATH at runtime does no good, as it is already cached by the linker, so we set it, and restart the program with the original arguments. This library should be used before any other libraries to make sure it works correctly. An alternative would be to reset LD_LIBRARY_PATH and any environment variables in a shell wrapper, and then run your program from the wrapp +er. =cut