use warnings; use strict; my %data; while () { my @cols = split; push @{ $data{first} }, $cols[0]; push @{ $data{last } }, $cols[1]; push @{ $data{phone} }, $cols[2]; push @{ $data{email} }, $cols[3]; } for my $item (qw(first last phone email)) { print "$item\n"; print "$_\n" for @{ $data{$item} }; print "\n"; } __DATA__ John Smith 1234 lala@lala.com Peter Jones 6789 ttt@yahoo.com George Lukas 9086 lll@hotmail.com