use strict; use warnings; use List::Util qw(reduce); my $maxkey = reduce { $hash{$a} > $hash{$b} ? $a : $b } keys %hash; my $minkey = reduce { $hash{$a} < $hash{$b} ? $a : $b } keys %hash; @hash{$minkey,$maxkey} = @hash{$maxkey,$minkey};