Alright. The ordering you're getting now is alphabetical, as a result of sort keys %data.
I can't see an ordering in the series "x", "y", "a", "z". The only way I can see to do that is to define it explicitly, something like this:
foreach my $key (qw(typex typey typea typez))
If there is an order to that series that I'm not seeing, you may be able to capture the logic in a custom sort function. Look up the sort docs for more info.