use Getopt::Long; Getopt::Long::Configure( 'permute' ); my( $a, $b ); GetOptions( 'a!' => \$a, 'b!' => \$b, '<>' => \&process, ); sub process { ... } # call with args like -a foo bar -noa -b baz