ported to PERL