open( IN2, $inf2 ) or die "Can't open $inf2: $!"; while () { next unless ( /.:./ ); my ($key,$val) = split( /:/, $_, 2 ); # error checking similar to what was done for $inf1 # ... # if $key did not occur in $inf1, and if this means that you # don't want to list it in the final output, then don't put # it into the hash in the first place unless ( exists( $file1{$key} )) { warn "$inf2:$.:Key $key not found in $inf1\n"; next; } $file1{$key} .= ";$val"; } close IN2;