use strict; use warnings; my $gendata = './gen.dat'; open GENDAT, "< $gendata" or die "can't open $gendata $!"; my @count; while (){ push @count, $_; } close GENDAT; my $a=shift @count; my @families=split(/\s+/,$a); my $b=0; foreach my $c(@count){ my @state; push @state, split(/\s+/,$c); print $state[0].' '; for($b=0;$b<=$#state;$b++){ print $families[$b].' ' if $state[$b] eq '1'; } print $/; } exit (0);