my $stringified; { local $/; # defaults to undef open my $fh, '<', './demo.mail'; # 3-arg open is nice $stringified = <$fh>; } # input's done, end-of-block closes the file and reverts to normal i/o my @cmd = qw( /usr/lib/dovecot/deliver -f test@somedomain.com -d test@mailtask.dom ); open( CMD_OUT, '|-', @cmd ) or die $!; print CMD_OUT $stringified; close CMD_OUT;