my $verbose = 1; my $r_cat = 'ssh %s cat "%s" |'; # host, file sub r_open { my ($spec) = @_; my ($host,$file) = split /:/, $spec,2; my $cmd = sprintf $r_cat, $host, $file; print "Opening [$cmd]\n" if $verbose; open my $fh, $cmd or die "Couldn't open remote file: $cmd: $!/$?"; $fh }; my $fh = r_open('user@host:some/file'); while (<$fh>) { chomp; print "I read line '$_'\n"; };