better perl function