open my $fh, '|-', 'mailx -s "List report" test@mail' or die "ERROR: Couldn't open pipe: $!"; print $fh $generatedMailText or die "ERROR: Couldn't write to pipe: $!"; close $fh or die "ERROR: Closing pipe failed: $!";