#!/usr/local/bin/perl

while (<>) {

    if (/^[0-9]+/) {
	$msg_num = $_;
    }
    elsif (/^Subject:/) {
	s/Subject: //;
	$subj{$_} .= $msg_num;
    }		
    else {
	die "Error\n";
    }
}


foreach $key sort((keys %subj)) {
    print "$key$subj{$key}";
}
