##
if ( $ref >= 1 and $ref <= 8 ) { ... }
####
if ( $ref =~ /^[1-8]$/ ) { ... }
####
use v5.10;
use strict;
use warnings;
my @tests = qw(1 9 17 25 33);
my $range_25_32 = [25..32]; # alternatve, maybe(?) faster
for my $ref ( @tests ) {
given ( $ref ) {
when ( [1..8] ) { say "A $ref" }
when ( [9..16] ) { say "B $ref" }
when ( [17..24] ) { say "C $ref" }
when ( $range_25_32 ) { say "D $ref" }
default { say "ELSE $ref" }
}
}
####
A 1
B 9
C 17
D 25
ELSE 33