use Data::Dumper; use Tie::SortHash; %hash = ( x=> 'line 1', z=> [ 1, 2, 4], y=> { file=> 'test.txt', length=> 200, type => 'ASCII' }, a=> 'line 2' ); tie %hash, 'Tie::SortHash', \%hash; print Dumper(\%hash);