use strict; use warnings; use Data::Dumper; my @aFiles; # <== array instead of my $i my %hARGV = map { if (/^--(\w+)=(\w+)$/) { # option => value $1 => $2; } elsif (/^--(\w+)/) { # flag => 1 $1 => 1 } elsif (m{^[\w/]}) { push @aFiles, $_; # <== put filenames into an array (); # <== don't put anything into hash (yet) } else { # bad argument - add nothing to the result hash warn "Invalid option: <$_> - options must begin with " ."-- or be a legal file name"; (); } } @ARGV; $hARGV{files}=\@aFiles if @aFiles; # <== _now_ put the files in the hash print Dumper(\%hARGV);