#! /usr/bin/perl # vim:ts=4 sw=4 sts=4 et nu fdc=3: use strict; use warnings; use Getopt::Long; my $x = "unset"; GetOptions( 'x:s' => sub { $x = $_[1] ? $_[1] : 'true' }, ) or exit 255; print "$x\n"; #### $ perl /tmp/getopt.pl unset $ perl /tmp/getopt.pl -x true $ perl /tmp/getopt.pl -x foo foo