while (<$CSV>) { chomp; # assume csv is SHIP1,DATETIME,LATITUDE,LONGITUDE. # modify accordingly.. my ($shipname, $datetime, $latitude, $longitude) = split(/\,/$_); my %today_details = (datetime => $datetime, latitude => $latitude, longitude => $longitude); # this is what will get pushed on the arrayref my @arr = @{$SHIPS{$shipname} || []}; # get curr contents push (@arr, \%today_details); # push today's data $SHIPS{$shipname} = \@arr; # push back } # that's you done with the merge