One way to keep that flexibility would be to use something like
Getopt::Long so that you could specify multiple items of interest on the command line which would populate an array. (Best to have a look at the documentation for
Getopt::Long as I don't have an example to hand.) Then from the array create a compiled regular expression using the pipe symbol for alternation to use in the
grep. If you didn't specify anything on the command line the array would be empty so in that case
push (or
unshift a . (dot) onto the array so the regex would match anything.
use strict;
use warnings;
use Getopt::Long;
my @wanted = ();
GetOptions(q{want=s}, \@wanted);
push @wanted, q{.} unless @wanted;
my $rxWanted;
{
local $" = q{|};
$rxWanted = qr{@wanted};
}
...
for my $key ( grep { m{$rxWanted} } keys %$info }
{
...
}
Again, not tested but I think the concept is sound.
Cheers,
JohnGG