#!/usr/bin/perl use strict; #https://perlmonks.org/?node_id=11121090 use warnings; my @handles = map { open my $fh, '>', "tmp.$_" or die; $fh } split /\t|\n/, ; while( ) { my @data = split /\t|\n/; print { $handles[$_] } $data[$_], "\n" for 0 .. $#handles; } close $_ or die for @handles; __DATA__ id name position 1 Nick boss 2 George CEO 3 Christina CTO