use strict; use Expect; my $ex = Expect->spawn(undef, "Command foo") or die $! $ex->expect(undef, "-re", "Do you want to read the file"); $ex->send("1\n");