use Getopt::Std; sub foo{ my($opt_a, $opt_b, $opt_c, $opt_d); getopts('abc:d:'); ...}