my @ids = qw(101 102 103 104 105); foreach my $id ( @ids ) { my $link = $mech->xpath( "//a[text()='MY IMAGE $id']", single => 1 ); $mech->click($link); $mech->sleep(1); my $resources = $mech->getResourceTree_future()->get; my @images = grep { $_->{type} eq 'Image' } @{$resources->{resources}}; print @images, "\n"; # this shows that the information in the array is not resetting my $image = $mech->getResourceContent_future( $images[0]->{url} )->get->{content}; open my $fh, '>:raw', $id.'.jpg'; print $fh $image; }