http://www.perlmonks.org?node_id=1045081


in reply to Parsing commandline with subcommands

1. pass all possible options for command and subcommands to Getopt::Long (passing all ever possible options is also necessary for consistency as options are auto-abbreviated)

2. After Getopt::Long processing @ARGV will contain non-options. Extract commands and subcommands from it

3. Analyze your options like

if delete $opts{myoption} ...

4. After analyze if you still have something unrecognized in @ARGV or %opts - that is unused options an you need to throw an error