horrible solution in perl