Reverse a hash: use key as the value, and value as the key
$hash{fruit} = apple; $hash{sandwich} = hamburger; $hash{drink} = bubbly; %reversed = reverse %hash; foreach $key (sort keys %reversed) { print "$key => $reversed{$key}\n"; }