use Win32::Console qw( CTRL_C_EVENT ); my $pid = open(my $fh_from_child, "$cmd |"); my $output = ''; while (<$fh_from_child>) { $output .= $_; if ( /waiting for control c/i ) { Win32::Console->GenerateCtrlEvent(CTRL_C_EVENT, $pid); } } close($fh_from_child); #### use IPC::Open3 qw( open3 ); use Win32::Console qw( CTRL_C_EVENT ); my $pid = open3('<&STDIN', my $fh_from_child, '>&STDERR', 'perl', @args); my $output = ''; while (<$fh_from_child>) { $output .= $_; if ( /waiting for control c/i ) { Win32::Console->GenerateCtrlEvent(CTRL_C_EVENT, $pid); } } close($fh_from_child); waitpid($pid, 0);