Added code from perl commit