Several structures are possible. I've used a HoHoA here. You might want to strip spaces from the hash keys if you have to make many references to them in your code.

#! perl -slw use strict; use Data::Dump qw[ pp ]; my %data; chomp( my @L1Headers = split "\t", scalar <DATA> ); chomp( my @L2Headers = split "\t", scalar <DATA> ); @data{ @L1Headers } = map{ +{ map{ $_ => undef } @L2Headers[ 0, 1 ] } } 1 .. @L1Headers; while( <DATA> ) { chomp; my @values = split "\t"; for my $l1 ( @L1Headers ) { for my $l2 ( keys %{ $data{ $l1 } } ) { push @{ $data{ $l1 }{ $l2 } }, shift @values; } } } print pp \%data; ## "What's Data Set 1's y value at Data Set 3's x3 value?" for ( 0 .. $#{ $data{ 'Data Set 1' }{ 'X units' } } ) { $data{ 'Data Set 3' }{ 'X units' }[ $_ ] eq 'x3' and print "DS3-X == x3, DS1-Y == ", $data{ 'Data Set 1' }{ 'Y units' }[ $_ ]; } __DATA__ Data Set 1 Data Set 2 Data Set 3 X units Y units X units Y units X units Y units x1 y1 x1 y1 x1 y1 x2 y2 x2 y2 x2 y2 x3 y3 x3 y3 x3 y3

Outputs

c:\test>junk2 { "Data Set 1" =>{ "X units" =>["x1","x2","x3"], "Y units" =>["y1","y2 +","y3"] }, "Data Set 2" =>{ "X units" =>["x1","x2","x3"], "Y units" =>["y1","y2 +","y3"] }, "Data Set 3" =>{ "X units" =>["x1","x2","x3"], "Y units" =>["y1","y2 +","y3"] }, } DS3-X == x3, DS1-Y == y3

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Help munging tabular data by BrowserUk
in thread Help munging tabular data by c4onastick

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.