use 5.012; while (my ($idx, $val) = each(@array)) { $hash{$val} = $idx; }