I did not try that. But I got it to work this way
use APR::Util();
@hashpasswd = split(":",chomp($yppasswd = `ypcat passwd | grep $user:`));
$ok = APR::Util::password_validate($passwd, $hashpasswd\1\);
if($ok == 1) { ## Valid User
}else { ## Invalid user
}
Thanks for the reply!