my %opts = ( # %known_opts enumerates allowed opts as well as specifies default # and initial values my %known_opts = ( 'debug' => 0, 'verbose' => 1, 'log' => 'log.txt', # default value 'file' => '', # actually like declaration of option ), #options itself my %specified_opts = ( (map {/^--([\-_\w]+)=(.*)$/} @ARGV), # --opt=smth (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV), # --opt --no-opt --noopt ), ); die "option '$_' is not recognized" for grep {!exists $known_opts{$_}} keys %specified_opts; @ARGV = grep {!/^--/} @ARGV; # then normal program goes here