improve perl code