Getopt::Long::GetOptions( 'u=s' => \$user, 'p=s' => \$passwd, 's=s' => sub { local *_ = \$_[1]; /^([^:]+):(\d+)$/ or die("Invalid format for option s.\n"); $host = $1; $port = $2; }, 'help' => \$help, # Will also handle -h ) or error_detect("3 Invalid commmand line options."); if ($help) { die("usage: ...\n"); }