use strict; use warnings; my %hash; #declaring hash for storing the data open FH, ") { #reading data from file if(/^Artist:\s*(.*)$/) { #checking whether its first artist details $i++; #incrementing the iterator for storing the details push @{$hash{$i}}, $1; #pushing the artist name to array while() { #continue reading the file to get artist details if(/^Artist:\s*(.*)$/) { #checking whether particular artist details completed $i++; #incrementing the iterator for storing the details push @{$hash{$i}}, $1; #pushing the artist name to array last; #break the loop } else { @arr=split(':'); #splitting the field name and value $arr[1]=~s/\s//g; #removing the unwanted spaces in file push @{$hash{$i}}, $arr[1]; #storing the further informations into array } } } else { @arr=split(':'); #splitting the field name and value $arr[1]=~s/\s//g; #removing the unwanted spaces in file push @{$hash{$i}}, $arr[1]; #storing the further informations into array } } my @fields=('Artist','Title','Album','Year','Genre'); #storing the field names in the file in order print "$_\t" for @fields; #printing the column headings print "\n-------\t-----\t------\t----\t-----\n"; #printing the ----- after each column for my $key (sort keys%hash) { #getting the records in order from hash my $j=0; print $hash{$key}->[$j++]." " while($j<5); #getting all data of artist from hash and printing it print "\n"; #printing newline for differentiating the records }