I'm running a system command and waiting for output matching a specific pattern, e.g:
open(my $fh, '-|', 'echo line 1; sleep 20; echo line 2');
while (<$fh>) {
print && last if /1/;
}
close $fh;
This will print line 1
and leave the loop but won't exit until the external command has completed.
How can I allow the script to exit immediately after matching the required output?