use strict; use warnings; use diagnostics; use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use IO::Handle; my $Proxy_Username='admin'; my $Proxy_Password='adminpw'; my @Proxies = ( "http://proxy1:23651/proxy-proxy1-proxy/bin/sitemon?doit HTTP/1.0", "http://proxy2:23651/proxy-proxy2-proxy/bin/sitemon?doit HTTP/1.0", "http://proxy3:23651/proxy-proxy3-proxy/bin/sitemon?doit HTTP/1.0", "http://proxy4:23651/proxy-proxy4-proxy/bin/sitemon?doit HTTP/1.0" ); my @Requests; for my $URL (@Proxies) { # Better outside the loop. my $Request = HTTP::Request->new(GET => $URL); $Request->referer("http://wizard.yellowbrick.oz"); $Request->authorization_basic($Proxy_Username,$Proxy_Password); push @Requests, $request; } STDERR->autoflush(1); STDOUT->autoflush(1); my $UA = LWP::UserAgent->new(); # No point re-creating $UA each time in the loop $UA->agent("Mozilla/4.7 [en] (WinNT; I)"); # The parameters don't change. $UA->timeout(15); # Keep them outside the loop. $UA->max_size(5000); my $delim = '--THIS_STRING_NEVER_HAPPENS'; while (sleep 60) { # Why 1==1 (just 1 would do) but this is better. # No need to call time(), it's the default. # No need to name it if you only going to print it. print scalar localtime()," --> "; # As I recently learnt, the scalar is important. foreach my $Request (@Requests) { # Note: named loop counter; not my $Request = $_ inside. my $Response = $UA->request($Request); print "something wrong happened contacting $URL....\n" and next if $Response->is_error(); # Not everyone agrees with this syntax # everything went ok my $Content = $Response->content(); # Rather than break the data into lines and the loop over the lines, break out the piece you want # Rather than use a regex for a static string, use index. my $first = index( $Content, $delim , 0 ) + length $delim; my $second = index( $Content, $delim , $first ); # I'd be tempted to print out the value of $second-$first, so that you may more closely tailor # the max-size parameter. You could also look for a header of X-Content-Range which the user agent # adds if the the size of the buffer requested was exceeded (See LWP::UserAgent docs) my $NewContent = substr( $content, $first, $second ); # Now we have a whole page in $new, we can break just this bit up @NewContentArray=split(/\n/,$Content); # I'll have to take your word that this does what you need it to do. # The value 14 will possibly need adjusting. if ($NewContentArray[14]=~/(>\s)(\d*)(\s<)/) { print $2," "; # get number of active processes } } print "\n"; }