my $cur_proxy = "http://$valid_routes[$j]"; # <--- Not working; my $cur_proxy = "http://$valid_routes[$j]/"; #<--- Works as a charm #### my (@agents, @raw_routes, @valid_routes); open( AGENTS, "<", "/etc/squid/ua.cfg" ); while( ) { s/#.*//; next if /^(\s)*$/; chomp; push @agents, $_; } close(AGENTS); open( ROUTES, "<", "/etc/squid/repeater/lib/routes.cfg" ); while( ) { s/#.*//; next if /^(\s)*$/; chomp; push @raw_routes, "$_,ENABLED"; } close(ROUTES); my $ua = LWP::UserAgent->new(); sub cb { my($request, $ua, $h) = @_; $#valid_routes = -1; my $i = $#agents + 1; $i = rand($i); $i = int $i; foreach my $item (@raw_routes) { $item =~ s/,ENABLED//; push @valid_routes, $item unless $item =~ m/DISABLED/; } my $j = $#valid_routes + 1; $j = rand($j); $j = int $j; my $cur_agent = $agents[$i]; my $cur_proxy = "http://$valid_routes[$j]"; $request->proxy_authorization_basic( 'uname', 'passwd'); $ua->proxy(['http'], $cur_proxy); $request->header('User-Agent' => $cur_agent); $ua->timeout(120); } $ua->add_handler( request_preprepare => \&cb, { m_method => 'GET' } );