#!/usr/bin/perl use warnings; use strict; my $file1=<) { chomp $line; my ($key,@vals) = split ',',$line; $hash{$key} = [@vals]; } # process file2, modify the memory hash table open (FILE2, '<', \$file2) or die "$!"; while (my $line = ) { chomp $line; my ($key,$val1) = split ',',$line; $hash{$key}[0] = $val1 if $hash{$key}; } # dump the hash table foreach my $key (sort keys %hash) { print "$key,", join(",",@{$hash{$key}}),"\n"; } __END__ Prints: "A123","valueA1","valueB1" "B234","valueA2","valueB2" "C345","valueX1","valueB3" "D456","valueX2","valueB4" "E567","valueA5","valueB5" "F678","valueA6","valueB6"