my $linenum=2; my $linetoadd="Something\n"; my $i; while(<>){ ++$i; if($i==$linenum) {print;print $linetoadd;} else {print;} }