#! /usr/local/bin/perl open (TEXT_FILE, "file1.txt"); while ($line = ) { if ($line =~ m/ERROR/) { $c = 0; while ($c <= 10) { $nextline = ; printf ("$nextline"); $c = $c + 1; } } } close (TEXT_FILE);