i want to makethis script output in the order that I want because it outputs in a silly order? how?

use CGI;
$query = new CGI;

open (PROFILE_OUTPUT, ">> profiles.txt") or die "Can't open profiles.txt";

print $query -> header;

#copy query_string into new variable
$form_info = $ENV{'QUERY_STRING'};

@input_pairs = split (/[&;]/, $form_info);

%input = ();
foreach $pair (@input_pairs) {
$pair =~ s/\+/ /g;

($name, $value) = split(/=/, $pair);

$name =~ s/%([A-Fa-f0-9]{2})/pack("c", hex($1))/ge;
$value =~ s/%([A-Fa-f0-9]{2})/pack("c", hex($1))/ge;

$input{$name} = $value;

print "<html><head><title>Profiles</title></head><body>\n";
print "<H1></H1>\n";

foreach $key (keys %input) {
print PROFILE_OUTPUT "$key : $input{$key}";
print PROFILE_OUTPUT "\n";

#print $query->redirect('thankyou.html');

open (INPUT, "< thankyou.html") or die "can't open thankyou.html";
while (<INPUT>) {
close INPUT;

print "</body></html>\n";