while($line = ){ chomp $line; ($junk,$o_country,$o_province,$o_tcenter,$o_address,$o_city,$o_stprov,$o_mailcountry,$o_postalcode,$o_firstname,$o_lastname,$o_title,$o_phone,$o_fax,$o_date) = split(/\|/,$line); #the hashes are filled using the test center as the key $testcenters{$o_city} = $o_tcenter; $centercity{$o_tcenter} = $o_city; ... (more values stored) @mycenters = sort byString keys %testcenters; #returns list of centercity in alpha order foreach $city(@mycenters){ foreach $center($testcenters{$city}){ print "$testcenters{$city}
"; #print testcenter name ... (print more stuff here) } }