$check = <<'CMD'; for i in /home/* do echo $i done CMD open(SSH, "| ssh sshtest\@localhost -T"); print SSH $check; close(SSH) or die "$!";