opendir (ID, "$dir"); @dirlist = readdir(ID); closedir(ID); foreach $inode (@dirlist) { $i++; print "Files processed: $i\n"; next if $inode =~ /^\./; my $sfile = $dir . $inode; open (IF, "<$sfile"); @fcont = (); close (IF); open (OF, ">$sfile"); foreach $line (@fcont) { if ($line =~ /themark/) { print "starter string found\n"; $flag = 1; next; } if ($flag == 1) { if (!($line =~ /\w+/)) { $flag = 0; next; } else { print OF $line; } } } close (OF); }