my %keys = keys %data; my $hkey = $data{$i}; if ((my @found = grep /^$hkey$/, %keys) > 1) { $hkey .= '_'; } $dataPos{$hkey} = $i;