You can try
use Data::Dumper;
local $Data::Dumper::Sortkeys = 1;
# using custom sort function
# local $Data::Dumper::Sortkeys = sub { [ sort keys %{+shift} ] };
print Dumper {
car => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
bus => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
tr => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
}
}
output
$VAR1 = {
'bus' => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
'car' => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
},
'tr' => {
'10' => 'y',
'11' => 'y',
'12' => 'y',
'13' => 'y'
}
};
From perldoc Data::Dumper
$Data::Dumper::Sortkeys
Can be set to a boolean value to control whether hash keys are dumped in sorted order. A true value will cause the keys of all hashes to be dumped in Perl's default sort order. Can also be set to a subroutine reference which will be called for each hash that is dumped. In this case Data::Dumper will call the subroutine once for each hash, passing it the reference of the hash. The purpose of the subroutine is to return a reference to an array of the keys that will be dumped, in the order that they should be dumped. Using this feature, you can control both the order of the keys, and which keys are actually used. In other words, this subroutine acts as a filter by which you can exclude certain keys from being dumped. Default is 0, which means that hash keys are not sorted.