#!/usr/local/bin/perl -w use strict; use LWP::Simple; $_ = get("http://classics.mit.edu/Lao/taote.mb.txt") or die "The page that can be fetched is not the true page\n"; my $chapter = 1 + int(81 * rand()); my $end = $chapter == 37 ? '\n-------' : $chapter == 81 ? '\nTHE' : ('\nChapter\s+' . ($chapter + 1). '\s*\n'); /^(Chapter\s+$chapter\s*\n.*?(?=$end))/ms && print $1;