my $retry_count = 0; while(1){ $rc = eval{$ssh->login();}; last if defined $rc; last if $retry_count >= $max_retry_count; $retry_count++; sleep 1; }