#!C:\perl\bin\perl.exe use warnings; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = 'https://webmail.my_university.edu'; $mech->get($url); # login $mech->submit_form( form_number => 0, fields => { imapuser => 'c4onastick', pass => 'my_password_here', } ); # Navigate back to the first page that contains the most recent messages $mech->follow_link(url_regex => qr/page=1/ ); # Find all links (messages) with Lab 2 in the subject my @links = $mech->find_all_links( text_regex => qr/lab\s*2/i ); my $content; foreach my $link (@links) { print $link->url."\n"; print $link->text."\n"; print "Following...\n"; $mech->follow_link( url => $link->url); $mech->follow_link( url_regex => qr/\.xls/i ); #link to the attached excel file $content .= $mech->content; # this might be where it is breaking down last; # Jump out after one for testing $mech->back; } mkdir "Eng_files", 0755 or die "Couldn't create directory: $!"; chdir "Eng_files" or die "Can't change directory: $!"; open(FH, ">", "test.xls"); print "Writing out...\n"; print FH $content; print "Done.\n\n";