#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $filename = 'pedigree_proband_testfile.txt'; my %n = (birth_year=> 13, motherID=> 4, individualID=> 2, gender => 5); my %mominfo; open my $f, "<", $filename or die "ERROR: Cannot open $filename:$!"; while (<$f>){ chomp; my @c = split /\t/, $_; my $currentMomID = $c[ $n{motherID} ] || $c[ $n{individualID} ] or die "No Mother ID in record nbr $.=$_;"; my $currentMom = $mominfo{ $currentMomID } ||= {}; # Create an empty mom if she does not exist if ($currentMomID == $c[ $n{individualID} ]){ print "This is Mom ($currentMomID)'s main record: $_\n"; $currentMom->{birth_year} = $c[ $n{birth_year} ]; }else{ push @{ $currentMom->{CHILDREN} }, {ID=> $c[ $n{individualID} ] , birth_year => $c[ $n{birth_year} ], gender => $c[ $n{gender} ]}; } } print Dumper \%mominfo;