#!/usr/bin/perl -w use strict; my %hash = (1 => 'foo', 2 => 'bar', 3 => 'asdf', 4 => 'blah', 10 => 'woah'); delete $hash{3}; FixHash(\%hash); print "$_ : $hash{$_}\n" for sort { $a <=> $b } keys %hash; sub FixHash { my $hashref = shift; my $index = 0; for my $key ( sort { $a <=> $b } keys %$hashref ) { $index++; next if $key == $index; $hash{$index} = delete $hash{$key}; } }