Just an update on this: As of now I am trying with the sort option as mentioned by salva. for my $key(sort keys %hash) { print FH1_sorting "$key -> $hash{$key}"; } This is working.But the problem here is, it is consuming all of systems memory 12GB and even after sort, the script is not getting terminated, but shows memory consumption at 99% for an indefinite amount of time. I have not looked at the GRT sort yet. Is there any solution for this memory consumption of 99%? Or should I to concentrate on GRT sort? Please advise