use strict; use warnings; use Data::Dumper; # $Data::Dumper::Terse = 1; my %library; #this is where we store title, author, date my $i = 1; #iterator for hash key name while () { my ( $title, $author, $date ) = split /\|/, $_; # the '|' just seperates records chomp($date); #because date has newline read from my example push @{ $library{ $i++ } }, $title, $author, $date; #put it in the hash of arrays '%library' } foreach my $key ( sort { $a <=> $b } keys %library ) { #sort isnt necessary but i put it there to give you an example print "Book #$key\n"; print "Title: @{$library{$key}}[0]\n"; print "Author: @{$library{$key}}[1]\n"; print "Date: @{$library{$key}}[2]\n\n"; } # use Data::Dumper to quickly verify data; # print Dumper %library; __DATA__ Beginning Perl|Simon Cozens|May 25, 2000 Modern Perl|Chromatic|2012 Impatient Perl|Greg London|Feb 7, 2004 Extreme Perl|Robert Nagler|2004 Embedding Perl in HTML with Mason|Dave Rolsky, Ken Williams|Oct 2002