my $Usage = "Usage: $0 --min MIN --max MAX --in INFILE --out OUTFILE\n"; my %args; while ( @ARGV >= 2 ) { if ( $ARGV[0] =~ /^--(min|max|in|out)$/ ) { my $opt = substr( shift, 2 ); $args{$opt} = shift; } else { last; } } die $Usage if ( @ARGV or ( keys %args != 4 )); # all 4 args are mandatory, and only these 4 args are allowed # now use $args{in} instead of $input, etc...