use strict; my %hash = ( 1 => 'angel', 2 => 'buffy', 3 => 'cordelia', 4 => 'dawn', 5 => 'ethan', 6 => 'faith', 7 => 'giles' ); reorder(5,'up'); # ethan moves up: swaps place with dawn display(); sub reorder(){ my ($item,$direction) = @_; if($direction eq 'up'){ # coming soon -- 'down' my $tmp = $hash{$item}; # save ethan $hash{$item} = $hash{ ($item -1) }; # move dawn down to 5 $hash{ ($item -1) } = $tmp; # put ethan back as 4 } } sub display { print '-' x 30,"\n"; foreach my $key (sort (keys (%hash))) { printf("%12s is now number %d\n",$hash{$key},$key); } print '-' x 30,"\n"; }