I'm not sure if I understood all your requirements, but here is some WORKING code to get you started.
#!/usr/bin/perl use strict; use warnings; #https://perlmonks.org/?node_id=1230556 #Normal open & process Input file would be # open my $inp, "<", "Inp-file-name"; # while (<$inp>){ # .. process One record , now located in $_ # } # close $inp; my @New_file = ( # This tracks info for each output file {FILENAME=>"File-for-col1.txt", FH=>undef}, {FILENAME=>"File-for-col2.txt", FH=>undef}, ); for my $file(@New_file){ open $file->{FH}, ">", $file->{FILENAME} or die "ERROR: Cannot open $file->{FILENAME}: $!"; } while (<DATA>){ my ($header, @columns) = split ; print "DEBUG: hdr=$header .. got ", scalar (@columns), " columns\n +"; my $col_idx=0; for my $file(@New_file){ print {$file->{FH}} $columns[$col_idx],"\n"; $col_idx++; } } for my $file(@New_file){ close $file->{FH}; } __DATA__ MT-TA 5.36272153463324 21.4508861385329 8.04408230194985 3 +4.857689975116 0 0 0 13.4068038365831 MT-TC 24.1322469058496 160.881646038997 48.2644938116991 3 +7.5390507424327 45.5831330443825 0 0 104.573069925348 MT-TD 10.7254430692665 10.7254430692665 0 2.68136076731662 + 0 176.969810642897 1.34068038365831 445.105887374559

                As a computer, I find your faith in technology amusing.


In reply to Re: General Help/Advice Needed by NetWallah
in thread General Help/Advice Needed by PandaRaey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.