in reply to Map not giving me what I thought it would.

In the interest of making life easier, CPAN modules for processing of command line options include: Getopt::Std and Getopt::Long. These modules are very handy for processing command line options of the most commonly used forms.

With that out of the way, in order to make map work the way you'd like it to, you can use a pattern expression with capturing parentheses:

#!/usr/bin/perl print "\@ARGV: [@ARGV]\n"; my @my_args = map { /^-(.*)/ } @ARGV; print "\@my_args:\n"; print "$_\n" for @my_args;

map evaluates the block in list context. The pattern with capturing parantheses, when evaluated in list context, returns either the captured text, or an empty list. What this means is that new elements are added to @my_args only when the pattern matches. Notice that the argument "baz," which doesn't begin with minus, is not added to @my_args.

Example:

$ ./code.pl -foo=bar -bar baz
@ARGV: [-foo=bar -bar baz]
@my_args:
foo=bar
bar