use Getopt::Std; my $Usage = "Usage: $0 -u user -p passwd -h host:port\n" # or "$0 -f foo -b bar -z baz" for some other script # hash to hold option flags, default values: my %opt = ( u => 'me', p => 'secret', h => 'localhost:80' ); my $opts = join '', keys %opt; die $Usage unless ( getopt( $opts, \%opt ) and $opt{u} =~ /\w/ and $opt{p} =~ /\S/ and $opt{h} =~ /\w:\d+$/ ); # adjust or skip the sanity checks as you please