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;