#! /usr/bin/perl -w use strict; use threads; my $break = 0; $SIG{INT} = sub { $break=1; }; sub calculation { local $SIG{INT} = 'IGNORE'; print("calculating something\n"); 5; } my $thread = async(\&calculation); # Starting a co-process to read from. my $procid = open( READ, '-|', 'perl -e "$|=1; $SIG{INT} = \'IGNORE\'; for ($i=0;$i<10;$i++) {print \"Line $i\n\"; sleep 1;}"' ); # Reading from co-process. until ($break) { my $line = ; last unless defined $line; print $line; } if ($break) { kill('ABRT', $procid); } close(READ); print $thread->join() ."\n";