Getopt::Long::GetOptions( 'f=s{1,}' => sub { foreach $_ (@_) { if ($_ =~ /\.xls$/) { print "This is if \$_: ".$_."\n"; push( @xls , $_ ); } elsif ($_ =~ /^f/) { next; } else { die ("Invalid format for option expected -f '*.xls'\n"); } } # End of foreach }, 'p=s' => sub { $_ = pop @_; /\.csv$/ or die ("Invalid format for option expected -p '*.csv'\n"); $csv = $_; } ) or usage("Invalid commmand line options.");