#!/usr/bin/perl -w use strict; my @keys = qw(one two three four five); my @vals = ( 1 .. 5 ); my %hash; @hash{ @keys } = @vals; print $_, " : ", $hash{$_}, $/ for keys %hash; #### my $smaller = @array1 > @array2 ? @array2 : @array1; for my $index ( 0 .. $smaller ) { my ($key, $val) = ($array1[$index] , $array2[$index]); if ( ! ref $key ) { if ( exists $hash{$key} ) { if ( ref $hash{$key} ) { push @{ $hash{$key} } , $val; } else { $hash{$key} = [ $hash{$key} , $val ]; } } else { $hash{ $array1[$index] } = $array2[$index]; } } }