#!/usr/bin/perl use strict; use warnings; my $i; for ($i = 0; $i < 5; $i++) { my $pid = fork; if ($pid) { next } exec 'ssh -t 127.0.0.1 "sudo echo hello"'; exit 0; } for (; $i > 0; $i--) { wait }