for(0..$#ary1) { unless (exists $hash{$ary1[$_]}) { $hash{$ary1[$_]} = $ary2[$_] } else { $hash{$ary1[$_]} = "$hash{$ary1[$_]:$ary2[$_]" } }