open(IN, "testB.txt") or die "Can't open testB.txt"; open(OUT, ">>testB8.txt")or die "Can't open the file for writing.\n"; %Array = (); #Create an empty array $/ = "" ; #Enable paragraph mode $* = 1; #Enable multi-line strings #Read each paragraph in as a string ($Profile). Split the #first line of the string so that the first line is the #$Key and the rest of the $Profile is the $Value. Then #input these into the %Array. while () { $_ = $Profile; ($Key, $Value) = split(/\r/, $Profile, 2); %Array = ("$Key" => "$Value"); } #For each $Key of the %Array, first sort the keys, then #print their associated values in the textfile OUT. foreach $Key (sort(keys(%Array))) { print (OUT "$Array{$Key} \n"); }