# (merging previous post) my @sorted_indices = sort {$a <=> $b} keys %upload; my %lookup_hash; @lookup_hash{@sorted_indices} = 0 .. $#sorted_indices; #### my $i = $lookup_hash{5}; print $x,"\n"; # prints 2 # get the next element from the hash my $next = $sorted_indices[$x + 1]; # $next holds 7 # get your image my $image = $uploads{$next};