in reply to how to get rid of pressing control+c keys

If you really want to drive the shell from a script have a look at the Expect module on CPAN.

Otherwise it might be easier to open the pipe(s) with this line;

my $pid = open3(\*IN,\*OUT, 0, "/bin/bash -c $cmd");
And move the assignment to the variable $cmd about the open3 call.

This way the eof(OUT) check will return true when the shell completes the task and exits. No ctrl+c needed.