Working perl conversion