Is there any way to prevent that "fork"?

AFAIK, no. See exec, system, and qx.

i need to run many externals commands from my Perl script and capture both return-code and STDOUT. These commands must run under a shell...

Be aware of The problem of "the" default shell. I also wrote about running external commands here. In this case I'd suggest something like IPC::System::Simple (note it doesn't capture STDERR, for that I'd suggest a different module):

use IPC::System::Simple qw/capturex EXIT_ANY/; my $out = capturex '/bin/bash', '-c', 'echo foo'; # or, if you don't want it to die on nonzero exit: my $out2 = capturex EXIT_ANY, '/bin/bash', '-c', 'echo bar && false';
i am looking for the "cheapest way" in terms of CPU and Memory load...

Without more information, this smells like premature optimization. What OS? What commands are you running; could they perhaps be replaced by Perl code? How many commands per second are you running? How fast do you need it to run, and have you written a prototype and measured its performance to see if it's good enough or not?

In reply to Re: Cheapest way for multiple external commands by haukex
in thread Cheapest way for multiple external commands by pedrete

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.