use strict; use warnings; my $file = "foo.txt"; # Set a default. use Getopt::Long; GetOptions( 'file=s' => \$file, # Default will be used unless --file ... appears on command line. ); print $file, "\n"; # prints 'foo.txt' unless the command line explicitly set something else.