#!/usr/bin/perl -w use strict; my @IDS; my $last = [0,0,0,0,0]; # In case the first line has fields missing while () { my @temp = split/\t+/; # allow multiple tab seperators. # set this element from the last if it's null $temp[$_] eq '' and $temp[$_] = $last->[$_] for 0 .. $#temp; push @IDS, $last = \@temp; # push saving a reference } print "@{$_}" for @IDS; =pod output c:\test>219201 1234 5 20021201 1 0 5678 0 20021202 0 0 5678 0 0 0 10 9120 10 20021211 0 0 6543 5 20021202 0 0 6543 0 0 0 5 6543 0 0 0 5 =cut __END__ 1234 5 20021201 1 0 5678 0 20021202 0 0 0 0 0 10 9120 10 20021211 0 0 6543 5 20021202 0 0 0 0 0 5 0 0 0 5