%hash = map {$_ => 1} ; print for (sort keys %hash); __DATA__ A=hello B=world B=planet C=universe #### A=hello B=planet B=world C=universe #### A=hello B=planet C=universe #### use strict; my %hash = map {/^(.*)=/ or die "Malformed input: $_"; $1 => $_} ; print for (sort values %hash); __DATA__ A=hello B=world B=planet C=universe