in reply to Append to correct place in a file

The easiest way is to rewrite the file with the "-i" command line option.

perl -i.bak EmpInfo

Program:

my $nameOfEmp = "whatever"; my $comments ="whatever"; my $found=0; while (<>){ if ($found) { if (!/^-/) { print $comments; $found = 0; } } elsif (/^$nameOfEmp/o) { $found = 1; } print; } print $comments if $found;