for my $try (1 .. 5) { debug("fetching HTML source: try $try of 5\n") if $debug; my $mech = WWW::Mechanize->new( autocheck => 0, ssl_opts => { verify_hostname => 0, SSL_version => 'TLSv1', }, timeout => 60, ); $mech->proxy('https', $args_hr->{proxy}); # Try::Tiny try { $mech->get( $url ); } catch { $err .= $_ if $_; }; my $text = $mech->content; $err .= "Can't fetch HTML source from $url!\n" if !$mech->success(); ... sleep 30; # before next try - if download was not succ. }