With Perl\'s Getopt::Long
you can easily define command-line options that take a variable number of arguments:
foo.pl --files a.txt --ve
I believe optparse
does not support what you require (not directly -- as you noticed, you can do it if you're willing to do all the extra work of a callback!-). You could also do it most simply with the third-party extension argparse, which does support variable numbers of arguments (and also adds several other handy bits of functionality).
This URL documents argparse
's add_argument
-- passing nargs='*'
lets the option take zero or more arguments, '+'
lets it take one or more arguments, etc.