use warnings; use strict; use File::Basename; use Data::Dumper; my %file_data; my @field_headers = (); open(OUT, ">inbound.txt") || die("can't open output file: $!"); # read all of the files dropped onto the batch file while (<>) { if(!m/^quit$/) { #grab and save the column headers on the first line if($. == 1) { #@field_headers = @{split_csv_string($_)} ; @field_headers = split_csv_string($_) ; # read the rest of the lines. each 'record' is a hash with the # field name as the key. each 'record' is added to the array of # records for that file } else { my %record; my $i = 0; foreach my $field_val ( split_csv_string($_) ) { $record{ $field_headers[$i] } = $field_val; $i++; } # ****** $file_data IS OK HERE! ****** push @{ $file_data{ $ARGV } }, \%record; } # reset line numbering on each input file } else { close(ARGV); @field_headers = (); } } sub split_csv_string { my ($str) = @_; chop($str); return split q|,|,$str; } print Dumper %file_data;