#!/usr/bin/perl use 5.020; use warnings; package PerlIO::via::NoLF { sub PUSHED { my $self= ''; bless \$self, shift; } sub FILL { my ($self, $fh) = @_; return defined $fh ? nolf(<$fh>) : undef; } sub WRITE { my ( $self, $text, $fh ) = @_; return 0 unless defined $text; return print $fh nolf($text); } sub nolf { $_[0] =~ s/\n(?!$)/\\n/gr; } } binmode STDOUT,':via(NoLF)'; my $cmd = qq{cat <<-ENDOFMESSAGE \none \ntwo \nthree \nENDOFMESSAGE}; print "Ausgabe am Bildschirm soll so auschauen - alles in einer Zeile:\n"; print $cmd; print "\n"; # cat <<-ENDOFMESSAGE \none \ntwo \nthree \nENDOFMESSAGE print "Ausgeführt muss es aber dann so werden:\n"; print `$cmd`; # one # two # three