A do-while loop should do the job without the goto:
my $output;
my $tries = 0;
do {
$output = `expect -f show_running_config.exp $router->[$IP]`;
if($?){ # subshell returns error
$tries++; # count a try
sleep 5; # pause
}
} while( $? and $tries < 4 ); # loop again if error and more tries
# was the last try unsuccessful?
if($?){ # last try was an error, ran out of tries
print "Unable to connect after $tries tries\n";
exit;
}
# go on to handle the response in $output
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.