foreach (@vidids) { my $uri = "https://www.googleapis.com/youtube/v3/videos?part=items(viewCount)&id=$idees&key=$API_KEY"; ##$idees is the 50-max comma separated string of video IDs my $result = get($uri); my $json = decode_json($result); for my $i( @{$json->{items}} ) { push @counts, $i->{viewCount}; } $idees = "the next 50 elements from @vidids..." #and keep looping until all are processed }