use Mojo::UserAgent; my @urls = qw( https://www.example1.com.json https://www.example2.com.json https://www.example3.com.json ); for my $URL (@urls){ my $ua = Mojo::UserAgent->new; my $data = $ua->get( $URL )->res->json; sleep(int(rand(60))); foreach my $comment ( @{$data} ) { foreach my $child ( @{ $comment->{'data'}->{'children'} } ) { #output path needs changing open(OUT, ">>C:/Users/user/perl_tests/redresults805.txt"); my $yprint = $child->{'data'}->{'body'} . "\n" if( $child->{'data'}->{'body'} ); print OUT "$yprint"; close(OUT); } } }