my $infile = "foo.txt"; my $outfile = "bar.txt"; open(IN, $infile) or die "Can't open $infile: $!"; open(OUT, "> $outfile") or die "Can't open $outfile: $!"; while() { if (/^REGULATION SLOT/..eof(IN)) { print OUT $_; } } close(IN); close(OUT);