command --option ... -- file1 file2 #### sub parse_args { my $last_opt = ''; my %opts; while (@ARGV) { my $arg = shift(@ARGV); if ($arg eq '--') { last; } elsif ($arg =~ s/^--?//) { $opts{$last_opt = $arg} = []; } else { push @{ $opts{$last_opt} }, $arg; } } unshift @ARGV, @{ delete $opts{''} } if $opts{''}; return \%opts; }