#!/usr/bin/perl use warnings; use strict; my @indices = qw( 1.1 1.4 5.33 6.1 7.23 7.133 10 11 ); sub i_le { my ($x, $y) = @_; my ($x_line, $x_char) = split /\./, $x; my ($y_line, $y_char) = split /\./, $y; $_ //= 0 for $x_char, $y_char; return $x_line < $y_line || $x_line == $y_line && $x_char <= $y_char } sub range { my ($in) = @_; for my $i (0 .. $#indices / 2) { return @indices[$i * 2, $i * 2 + 1] if i_le($indices[ $i * 2 ], $in) && i_le($in, $indices[ $i * 2 + 1 ]); } } use Test::More tests => 5; is_deeply [range('1.1')], [qw[ 1.1 1.4 ]]; is_deeply [range('1.2')], [qw[ 1.1 1.4 ]]; is_deeply [range('1.4')], [qw[ 1.1 1.4 ]]; is_deeply [range('7.50')], [qw[ 7.23 7.133 ]]; is_deeply [range('10.5')], [qw[ 10 11 ]];