for (sort { $shipto{$a}{i} <=> $shipto{$b}{i} } keys %shipto) { print qq| $shipto{$_}{label} $ref->{"shipto$_"} |; }