# Read the data table my @table; while (<>) { chomp; my ($start, $stop, $id, $id2) = split /\t/, $_; push @table, [ $start, $stop, $id1, $id2 ]; } # Patch up the data for (my $i=1; $i < $#table; ++$i) { # check surrounding items and patch the data, as needed . . . } # Print the new table for my $ar (@table) { my ($start, $stop, $id, $id2) = @$ar; print ..... }