foreach ( keys %hash1 ) { my $out = ( exists $hash2{$_} ) ? $hash1{$_} . "." . $hash2{$_} : $hash1{$_} ; print $out, "\n"; }