use strict; use warnings; my (@one, @two, @three); while () { chomp; /([^ ]+) ([^ ]+) ([^ ]+)/; push @one, $1; push @two, $2; push @three, $3; } print join("\n", join(' ', @one), join(' ', @two), join(' ', @three)), "\n"; __DATA__ 1 cow MM 2 cat DD 3 fly SS