$from = "news.dat.txt"; my %h; open(FILE, "$from") || die "Can't open $from!\n"; while () { chomp; ($title,$url,$site,$date,$description) = split(/~/,$_); # if the date has already been seen, tack this entry on to the hash value if( $h{$date} ){ $h{$date} .= "|$title~$url~$site~$description"; } # date hasn't been seen, so create a new hash entry else { $h{$date} = "$title~$url~$site~$description"; } } #sort the dates in desc. order foreach $key (sort {$b cmp $a} keys %h) { #do for each item for that date @items = split '\|', $h{$key}; foreach $item (@items) { #split back out the values and print the table my($title,$url,$site,$description) = split /~/,$item; print ""; print ""; print "
$title
$key,$site
$description

"; } }