#!/your/perl/here use strict; use warnings; use Getopt::Declare; my $option_spec = qq{ # note: required tab between last argument and description -x [ ] -x takes 1 or 4 args [required] -y [ ] -y takes 1 or 3 args [required] -z [] -z takes 1 or 2 args [required] At least one of these options is required, and all are mutually exclusive. [mutex: -x -y -z] Examples: $0 -x zero one two three $0 -y zero alpha beta $0 -z zero last_but_not_least }; my $options = Getopt::Declare->new( $option_spec ) or die "\n**** Error processing command line options, terminating $0\n"; sub do_something { print "@_\n"; } if ( $options->{'-x'} ) { if ( defined( $options->{'-x'}{''} ) ) { do_something("-x", $options->{'-x'}{''}, $options->{'-x'}{''}, $options->{'-x'}{''}, $options->{'-x'}{''} ) if $options->{'-x'} } else { do_something("-x", $options->{'-x'}{''} ); } } if ( $options->{'-y'} ) { if ( defined( $options->{'-y'}{''} ) ) { do_something("-y", $options->{'-y'}{''}, $options->{'-y'}{''}, $options->{'-y'}{''} ) if $options->{'-y'} } else { do_something("-y", $options->{'-y'}{''} ); } } if ( $options->{'-z'} ) { if ( defined( $options->{'-z'}{''} ) ) { do_something("-z", $options->{'-z'}{''}, $options->{'-z'}{''} ) if $options->{'-z'} } else { do_something("-z", $options->{'-z'}{''} ); } }