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