use strict; use warnings; use LWP::UserAgent; my @pages = ('http://www.perlmonks.org','http://perldoc.org'); my $ua = LWP::UserAgent->new; # the line count is global my $read_lines=1; foreach my $url (@pages){ my $response = $ua->get($url, ':content_cb'=>\&head_only); } sub head_only{ my ($data,$resp,$protocol) = @_; my @lines = split "\n", $data; foreach my $line (@lines){ if ($read_lines == 31){ # reset the line count $read_lines = 1; print +("=" x 70),"\n"; # die inside this callback interrupt the request, not the program!! # see LWP::UserAgent docs die; } else{ print "line $read_lines: $line\n" } $read_lines++; } }