use IPC::Cmd qw{run}; $ssh_cp_id = ''; $ssh_cp_id_result = run( 'command'=>"ssh-copy-id -i $path_pk $user\@$server 2>/dev/null", 'buffer'=>\$ssh_cp_id ); if($ssh_cp_id_result){ #print has no effect, as the password prompt got already displayed without being captured to the $ssh_cp_id: print $ssh_cp_id; }