use Mojo::UserAgent; my $url ='https://www.reddit.com/r/unitedkingdom/comments/58m2hs/i_danie+l_blake_is_released_today/.json'; my $ua = Mojo::UserAgent->new; my $data = $ua->get( $url )->res->json; foreach my $comment ( @{$data} ) { foreach my $child ( @{ $comment->{'data'}->{'children'} } ) { #output path needs changing open(OUT, ">>C:/Users/user/perl_tests/redresults221.txt"); my $yprint = $child->{'data'}->{'body'} . "\n" if( $child->{'data'}->{'body'} ); print OUT "$yprint"; close(OUT); } }