#!/usr/bin/perl -w use strict; open (F, "+<",$ARGV[0]); my $out = ""; while(){ chomp; $out .= $_."\tadd sth\n" if($.%2 == 0); } seek(F,0,0); print F $out; close(F);