#!/usr/bin/perl use strict; use warnings; my $infile = '/home/yanni/scripts/testfiles/list_names'; my $outfile = "$infile.tmp"; open (my $in, '<', $infile ) || die "Can't open $infile $!\n"; open (my $out, '>', $outfile) || die "Can't open $outfile $!\n"; while (<$in>) { print $out $_; if ($.== 3) {print $out "Simon\n";} } close ($in); close ($out); rename ($outfile, $infile) || die "Unable to rename: $!";