my @result; foreach my $c (@array) { next if $b =~ /^Individual/; next if $b =~ /^000\d+/; next if $b =~ /^\w+/ ; ($loga, $logb, $x, $y) = split (/ /,$c); push @result,$x,$y); } print join("\t",@result); #### while () { ... if ($line=~/^Individual) { my @array= split (/\s+/, $line); shift @array; #removes the 'Individual' string foreach (@array) { ... #process an 'Individual' line } } else { my @arrays= split (/\s+/, $line); my $year= shift @array; foreach (@array) ... #process a data line } }