in reply to Copying text between markers

Thank you all! I got some great ideas from that - I eventually used a while loop though:
#!/usr/bin/perl -w print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); opendir(DIR, "."); @files = grep( /\.tmp/, readdir(DIR) ); @files = sort(@files); closedir(DIR); foreach $file(@files){ $found = 0; open(FOO, "$file") or die "Cannot open. $!\n"; while (<FOO>){ print "Copying table from $file...<br>"; if ( $_ =~ m/<!--TABLE -->/ig){ $found = 1; } if ($found == 1){ open(FILE,">>filename2.txt") or die "Cannot open. $!\n"; print FILE $_; close(FILE); } if ( $_ =~ m/<!--\/TABLE -->/ig){ $found = 0; } } close FOO; }