open (INFILE, $infile) || die "but... $!"; open (OUTFILE, ">$outfile") || die "but... $!"; my @hold; while(){ if ($. < 12){ push @hold, $_; next; } if ($. == 12){ # grab some data from the 12th line # perform some funky manipulation on it print OUTFILE "new funky data from 12th line"; print OUTFILE @hold; next; } print OUTFILE $_; }