my $line = "desc\tdate\tdetails"; # This will be the newline @ARGV = "file.tab"; # Init input file $^I = ".bak"; # Inplace editing with a bak up file if (-z "file.tab") { # somehow set the file up with a fake line to chew on ??? } while (<>) { # if theres no more lines after if (eof(ARGV)) { # take a slice of the last line # the id number to be precise # add 1 to get the next id number for # the newline we're inserting # also put the rest of the line on the end # and piggy back the line onto the last line of the file $_ .= (split /\t/)[0] + 1 . "\t$line\n"; } print; }