my @inputs = $mech->find_all_inputs( type => 'image', name_regex => qr/$pattern1/, ); #the Pattern is simply a name that is unique to all the buttons I want to access foreach my $i(@inputs){ my $temp = $i->name(); $mech->click_button(name => $temp); $tempContent = $mech->content; &getDetails($tempContent); # this is another function using tokeparser to grab info from the page linked by the images content $goToMoreDetails = $mech->uri();#variable to grab the current url, for future use. $mech->back(); #returning to original page. }