#!/usr/bin/env perl use strict; my $user = 'brannont'; my @host = qw( secdevfdsapp01 dopey bonnie ) ; sub ssh_string { my $host = shift; sprintf "%s@%s", $user, $host } sub printchoices { print "\n\n"; print "ssh hosts\n"; print "---------\n"; for (my $i=0; $i <= $#host; ++$i) { printf "[$i] %s\n" , $host[$i] ; } } sub prompt { print "\n\nssh to: " ; } sub getchoice { prompt ; my $choice = ; chomp $choice; return $choice; } sub mainloop { { printchoices; my $c = getchoice ; return $c if $c >= 0 and $c <= $#host ; redo; } } my $c = mainloop ; my $host = $host[$c] ; my $sshstr = ssh_string($host) ; print $sshstr, "\n" ; exec 'ssh', $sshstr ;