use strict; use warnings; use Data::Dumper; use WWW::Mechanize; my %links; 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"; my @link = $mech->find_all_links(tag => "a", class => "foo") or die "can't find link"; $links{$cnt} = \@link; } # Do something with @link here, after the loop is done print Dumper \%link; # Show the content of %link