Hi shalgham,
Without removing anything from previous great post, I think ( that is if I get your question right ) what you need do is get the index of the column you wanted and print it out. Since all the values for the column you wanted follow the same.
Something like this, using a modified data given by InfiniteSilence

#!/usr/bin/perl -l use warnings; use strict; # get the header into an array my @header = split /\s+/, <DATA>; # conjure a regex using the name of columns you wanted # which is the array you have my $to_find = join( '|' => qw(nat pls kac) ); my $reg_to_use = qr/$to_find/; # get the index of the header you need my @index = grep { $header[$_] =~ /$reg_to_use/ } 0 .. $#header; print join( "\t" => @header[@index] ); while (<DATA>) { print join( "\t" => ( split /\s+/, $_ )[@index] ); } __DATA__ nat pls fof tri pls fof tri kac 0.1 0.1 0.23 0.1 0.1 0.23 0.1 0.31 2.3 1.8 3.2 4.4 1.8 3.2 4.4 3.21 5.5 3.2 8.6. 7.9 3.2 8.6. 7.9 2.89
Output:
nat pls pls kac 0.1 0.1 0.1 0.31 2.3 1.8 1.8 3.21 5.5 3.2 3.2 2.89
Note: I don't know how your real dataset looks like, and the above 'might' not be the best in your situation but I can only hope this gives a head up.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

In reply to Re: searching an array member in file header and print a column by 2teez
in thread searching an array member in file header and print a column by shalgham

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.