#!/usr/bin/perl -p00 use warnings; use strict; open (my $fh, "<", "C:/songdata1.txt") or die "can't open the file: $!\n"; # $! gives a clue my %hash; while (<$fh>){ chomp; my @array = split /\n/, $_; for (@array) { my ($header,$info) = split /\s*:\s*/; # eliminate blanks before/after ':' $hash{$header} = $info; } write; } format TOP = Artist Title Album Year Genre ------ ----- ----- ---- ----- . format STDOUT = @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<< @<<< @<<<<<<<<<<<<< $hash{Artist}, $hash{Title}, $hash{Album}, $hash{Year}, $hash{Genre} .