#!/usr/bin/env perl use Modern::Perl; my %data; # HoAoA holding final data structure my @indexes; # array of indexes into %data based on coordinates my $header_line = ; # some of these steps could be combined; chomp $header_line; # including them for clarity my @headers = split ',', $header_line; shift @headers; # throw away SAMPLE for my $n (@headers){ my $x = $n/100_000; my $y = $n % 100_000; push @indexes, [ $x, $y ]; } while(){ chomp; my( $id, @bits ) = split ','; for my $i (0..@bits-1){ $data{$id}[$indexes[$i][0]][$indexes[$i][1]] = $bits[$i]; } } say "Expecting 0 0: ", $data{HG00553}[162][87365]; say "Expecting 1 1: ", $data{HG00638}[162][87851]; __DATA__ SAMPLE,16287215,16287226,16287365,16287649,16287784,16287851,16287912 HG00553,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00554,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00637,0 0,0 0,0 0,0 0,0 0,0 0,0 0 HG00638,0 0,0 0,0 0,0 0,0 0,1 1,0 0 HG00640,0 0,0 0,0 0,0 0,0 0,1 1,0 0