# 15 lines / 462 characters / 5 variables

my @headers = qw(to msg_num from msg_date subject);

open (MESSAGE, $messages) 
  or die "Couldn't open message file $messages: $!";
while (<MESSAGE>) {
  s/\cM$//;
  if (/==START==/) { 
    my (%message, $body);
    for (@headers) { chomp($message{$_} = <MESSAGE>) }
    push @unsorted, \%message;
    
    while (<MESSAGE>) {
      $body .= $_;
      last if /==END==/;
    }
    $unsorted[-1]{text} = $body;
  }
}
close MESSAGE;


