in reply to -x accepts up to 3 additional arguments

There seemed to be an inconsistency in the various example rules given for -x; whatever the case, the first step I would take is to define the usage rules clearly insead of by example, e.g.:

[-x argx1 [argx2 [argx3]]] [-y argy1 [argy2]]

or whatever it should be.

Although a module may or may not be suitable for this, my own approach when the requirement gets too deviant from norms is to:

1) define the rules in a control hash

2) hand-build the required getopts module, deriving everything from the rules you defined.

In this case, I get something a bit complicated that looks like this, but who knows, someone might know a module that does all this...(warning untested!)

my %controlCentre = (); $controlCentre{ ALLOWED }{ x }{ MIN } = 1; $controlCentre{ ALLOWED }{ x }{ MAX } = 3; ... etc. GetOpts( ctrl => \%controlCentre ); # # at this point actual options and arguments have been # loaded into the control hash in the form # $controlCentre{ ACTUAL }{ option-letter } = argument-array # sub GetOpts { my %par=(@_); while ( $ARGV[0] =~ /^\-(.)$/ ) { my $opt = $1; $par{ ctrl } -> { ALLOWED }{ $opt } or Usage( ctrl => $par{ ctrl }); shift @ARGV; my $minAllowed = $par{ ctrl } -> { ALLOWED }{ $opt }{ MIN }; my $maxAllowed = $par{ ctrl } -> { ALLOWED }{ $opt }{ MAX }; $par{ ctrl } -> { ACTUAL }{ $opt } = []; $aref = $par{ ctrl } -> { ACTUAL }{ $opt }; for ( my $i = 1; $i <= $maxAllowed; $i++ ) { if ( $ARGV[0] =~ /^\-(.)$/ ) { ( $i >= $minAllowed ) or Usage( ctrl => $par{ ctrl }); last; } else { push @$aref, shift( @ARGV ); } } } # leftovers must have disobeyed the rules... $ARGV[0] and Usage( ctrl => $par{ ctrl } ); } sub Usage { # even the Usage message is driven by the defined rules my %par = (@_); print STDERR "Usage: $0 "; my $allowRef = $par{ ctrl } -> { ALLOWED }; foreach ( sort keys %$allowref ) { print STDERR "-$_ "; my $minAllowed = $par{ ctrl } -> { ALLOWED }{ $_ }{ MIN }; my $maxAllowed = $par{ ctrl } -> { ALLOWED }{ $_ }{ MAX }; for ( my $i = 1; $i <= $minAllowed; $i++ ) { print STDERR "arg${_}${i} "; } $maxAllowed and print STDERR "[ "; for ( my $i = $minAllowed + 1; $i <= $maxAllowed; $i++ ) { print STDERR "arg${_}${i} "; } $maxAllowed and print STDERR "] "; } print STDERR "\n"; exit 1; }

-S