Perl port of when-rb