#!/usr/bin/env perl use strict; use warnings; use List::Util qw(sum); # For each $n, convert $n to hex digits, add the digits together. If the # result has more than one hex digit, repeat this process adding the # digits together. When there is only one hex digit remaining, if the # digit is a '5', an 'a', or an 'f', the original number was divisible # by 5. for my $n (1..100) { my $h = sprintf '%x', $n; while(length($h) > 1) { $h = sprintf '%x', sum(map {hex $_} split //, $h); } print "$n is a multiple of 5\n" if $h =~ m/^[5af]$/; }