use strict; use warnings; use Getopt::Long; # General default value my $foo = 'default'; # Let environment override the default if (defined $ENV{FUBAR}) { $foo = $ENV{FUBAR}; } # The command-line option overwrites if it exists GetOptions("foo=s"=>\$foo); print "The foo parameter is '$foo'\n"; #### $ perl foo.pl The foo parameter is 'default' $ export FUBAR='Gragnar' $ perl foo.pl The foo parameter is 'Gragnar' $ perl foo.pl -foo=BARBAZ The foo parameter is 'BARBAZ' $