#!/usr/bin/env perl -l use strict; use warnings; use Getopt::Long 'GetOptionsFromString'; my ($x, $y, $z) = qw{42 fred 1.0}; my %opts = ('x=i', \$x, 'y=s', \$y, 'z=f', \$z); print 'Option starting values:'; print "Options: x[$x] y[$y] z[$z]"; if (exists $ENV{USER_OPTS}) { GetOptionsFromString($ENV{USER_OPTS}, %opts); print 'After environment variable options processed:'; print "Options: x[$x] y[$y] z[$z]"; } if (@ARGV) { GetOptions(%opts); print 'After command line options processed:'; print "Options: x[$x] y[$y] z[$z]"; }