#! perl -slw use strict; my $tempdir = '/temp'; ## Read the first line of the file to determine how many columns my @fields = split ' ', <>; seek *ARGV, 0, 0; ## And rewind for the loop below. my @fhs; open $fhs[ $_ ], '+>', sprintf "$tempdir/%03d.tmp", $_ or die "Failed to open temp file $_; you probably ran out of handles: $!\n" for 0 .. $#fields; warn "opened intermediaries\n"; ## Read each line, split it and append each field to its file while( <> ) { printf STDERR "\r$.\t"; ## Activity indicator my @fields = split; printf { $fhs[ $_ ] } "%s ", $fields[ $_ ] for 0 .. $#fields; } warn "\nintermdiaries written\n"; seek $_, 0, 0 for @fhs; warn "intermdiaries rewound\n"; ## Read each tmp file back and write to stdout print do{ local $/; readline( $_ ) } for @fhs; ## Just truncate the tmp files to zero bytes warn "Done; truncating and closing intermediaries\n"; truncate( $_, 0 ) and close( $_ ) for @fhs; __END__ [ 7:06:52.07] c:\test>631400 junk.dat >junk.xdat opened intermediaries 5001 intermdiaries written intermdiaries rewound Done; truncating and closing intermediaries