use Expect; use IO::Stty; my $command = "adduser"; my @params = qw( --no-create-home --firstuid 4001 --ingroup clients --shell /bin/false --home /home/fred fred); my $exp = Expect->new("$command @params") or die "Cannot spawn $command: $!\n"; $Expect::Exp_Internal = 1; my $timeout = 5; $exp->expect($timeout, [ qr/UNIX password:/ => sub { my $exp = shift; $exp->send("sponge\n"); exp_continue; } ], [ qr/Full Name/ => sub { my $exp = shift; $exp->send("Mr Fred\n"); exp_continue; } ], [ qr/Number|Phone|Other/ => sub { my $exp = shift; $exp->send("\n"); exp_continue; } ], [ qr/correct/ => sub { my $exp = shift; $exp->send("y\n"); } ], );