use POSIX ":sys_wait_h"; ... # important: called within fork sub Send { my $message = shift; my $pid = open my $wh, '| mail ...'; print $wh $message; close $wh; waitpid $pid, 0; }