use strict; use warnings; my @col_names; open(my $result_fh, '<', 'file') # 3-arg safer or die("Unable to open input file: $!\n"); # $! meaningful while (<$result_fh>) { chomp(); # chomp safer my @fields = split(/;/, $_); if ($. == 1) { @col_names = @fields; } else { my %fields; @fields{@col_names} = @fields; # Do what you want here. print "$fields{name}, "; print "$fields{postcode}\n"; } }