# read a file and set a flag (boolean) if pattern is found # we then will print the following line and reset the flag open(OUT,$outputfilename)||die "Could not open $outputfilename for output\n$!\n"; open(FILE,$inputfilename)||die "Could not open $inputfilename for reading\n$!\n"; while(){ if($checked){ print OUT; undef $checked; next; } if(/pattern/){ $checked=1; next; } } close(FILE); close(OUT);