use strict; use warnings; use Getopt::Long; use vars qw($opt_u $opt_h $opt_a $opt_l); #Note that l=s says that l requires an option # l:s means that it is optional # I have chosen the option method here so that # I can handle it how I want programatically &GetOptions('l:s','u','h','a') || exit 1; print "Option found: u\n" if ($opt_u); print "Option found: h\n" if ($opt_h); print "Option found: a\n" if ($opt_a); if (defined $opt_l) { print "Option found: l\n"; if ($opt_l) { print " with value: $opt_l\n"; } else { print " No value specified.\n"; } }