struggling with perl wrapper and intermittent failures