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);