use strictures; use LWP::UserAgent; # my ($content,$decoded,$req,$res); # ^^^ No! Nothing in the full scope, please. my $ua = LWP::UserAgent->new; $ua->default_header('Content-Type' => 'application/json'); $ua->default_header('Accept' => 'application/json, text/javascript, */*; q=0.01'); while ( my $url = your_url_generator_lister() ) { my $response = $ua->get($url); # do whatcha gonna do with it. }