# 32 lines / 967 characters / 14 variables

  $recnum=-1;
  $linenum=0;
  open (HDR,"$messages");
    @AllLines=<HDR>;
  close (HDR);
  $numlines=@AllLines;
  for($xc = 0;$xc < $numlines;$xc++){
        $AllLines[$xc] =~ s/\cM//g;
        $AllLines[$xc] =~ s/\n//g;
  }  
 
  for($xc = 0;$xc < $numlines;$xc++){

     $t="";     # Initialize everything
     $n="";
     $f="";
     $d="";
     $s="";
     $m="";

     if ($AllLines[$linenum++] =~ /==START==/){
        $recnum++;
        $t = $AllLines[$linenum++];
        $n = $AllLines[$linenum++];
        $f = $AllLines[$linenum++];
        $d = $AllLines[$linenum++];
        $s = $AllLines[$linenum++];
        do {
          $m = $m . $AllLines[$linenum++] . "\n";
        } until ($m =~ /==END==/);

        $unsorted[$recnum]{"to"}=$t;
        $unsorted[$recnum]{"msg_num"}=$n;
        $unsorted[$recnum]{"from"}=$f;
        $unsorted[$recnum]{"msg_date"}=$d;
        $unsorted[$recnum]{"subject"}=$s;
        $unsorted[$recnum]{"text"}=$m;

     }
