http://www.perlmonks.org?node_id=11118404


in reply to Pass local bash script to remote host via SSH

use strict; use warnings; open(my $out_fh, "|-", qw'ssh <remotehost> bash -s') or die "Can't sta +rt ssh: $!"; print$out_fh <<EOF; <local bash script written here> EOF close $out_fh or die "Error flushing/closing pipe to ssh: $!";
see open, and Quote and Quote like Operators (watch the semicolon after <<EOF - the <<EOF syntactically stands in for the complete string)

Update:should you need variables interpolated in your 'ssh <remotehost> ...', you need to create the list in a different way, because qw doesn't interpolate variables.