$/ = "----- PAGE SEPARATAAAR -----\n"; while (<>) { chomp; # $_ now contains the HTML page } #### my $page = ''; while (<>) { if ( /xxx PAGE BOUNDARY \d+ xxx/ ) { output( $page ); $page = ''; next; } $page .= $_; }