# also declare other ctrl chars you need... my $ctrlD = "\x4"; my $escape = "\x1b"; #... more code here... cmd("Send all the\ncommands you need\nincluding a ${ctrlD}");