use warnings; use strict; use List::Util qw/max pairmap/; use Set::IntSpan; my @array = (1.1,1.4,5.33,6.1,7.23,7.133,10,11); my $input = 7.25; # check the maxmum number of digits after the decimal point my $maxlen = max map { length( (split /\./,$_,2)[1]//'' ) } @array; # build the set my $set = Set::IntSpan->new( [ pairmap { [$a,$b] } map { my @x = split /\./, $_, 2; sprintf "%d%0*d", $x[0], $maxlen, $x[1]//0 } @array ] ); # normalize the input die "Input too wide" unless $input=~/\A\d+(\.\d{1,$maxlen})?\z/; my $innorm = do { my @x = split /\./, $input, 2; sprintf "%d%0*d", $x[0], $maxlen, $x[1]//0 }; # lookup if ( defined( my $ord = $set->span_ord( $innorm ) ) ) { my ($x,$y) = @array[ $ord*2, $ord*2+1 ]; print "found $input in span $x-$y\n"; } else { warn "did not find $input in any of the spans\n" }