#! perl -slw use strict; my @matches = map $_ * 10, 1 .. 10; my @headers = map $_ * 5 +2, 0 .. 20; my $hdr = 0; for my $match ( @matches ) { $hdr++ while $headers[ $hdr + 1 ] < $match; printf "match at %d in section from %d - %d\n", $match, $headers[ $hdr ], $headers[ $hdr + 1 ] -1; } __END__ [16:20:40.99] c:\test>junk36 match at 10 in section from 7 - 11 match at 20 in section from 17 - 21 match at 30 in section from 27 - 31 match at 40 in section from 37 - 41 match at 50 in section from 47 - 51 match at 60 in section from 57 - 61 match at 70 in section from 67 - 71 match at 80 in section from 77 - 81 match at 90 in section from 87 - 91 match at 100 in section from 97 - 101