use strict; use warnings; use Data::Dumper; use WWW::Mechanize; my @link; for my $cnt (1..3) { my $url = "http://www.foo.com/p/$cnt"; my $mech = WWW::Mechanize->new(); $mech->get($url) or die "no such url"; push @link, $mech->find_all_links(tag => "a", class => "foo") or die "can't find link"; } # Do something with @link here, after the loop is done print Dumper \@link; # Show the content of @link