use Getopt::Long; my ( $timeout, $show_help ) = 30; unless ( GetOptions("timeout|t=i" => \$timeout, "help|h|?" => \$show_help) && $show_help ) { error_info(); } #### perl -w tmp.pl --help #### use Getopt::Long; GetOptions( "timeout|t=i" => \my $timeout, "help|h|?" => \my $show_help ) or die "bad options."; $timeout ||= 30; if ( $show_help ) { print "Showing help\n"; error_info(); }