More concise and idiomatic perl5

Here is a more concise and idiomatic version of the Perl 5 that still keeps the spirit of the original one.
I measured about 35% improvement over the original Perl 5 version.

Cc: @dagolden