#!/usr/bin/perl -w use strict; my @header = ('h1','h2','h3'); # I already know the headings my %values; # make a hash of hashes to remember the values while () { chomp; my @columns = split /\|/; my $unique = $columns[1]; # h2 is the unique identifier @{$values{$unique}}{@header} = @columns; } __END__ val1|one|1 val2|two|2 val3|three|3