compare the interval of 2 numbers of input2with interval of several numbers of input1

Help plz
Does any one have any idea how to compare interval ranges of 2 files.
finding 1-4 (1,2,3,4) of input2 in input1 of same key "a" values (5-10, 30-40, 45-60, 80-90, 100-120 ). Obviously 1-4 is not one of the range with in input1 a. so it should give out of range.
finding 30-33(31,32,33) of input2 in input1 "y"values (5-10, 30-40, 45-60, 80-90, 91-120 )..........................should give with in the range

note:the first interval of input2 (like 1-4 0r 30-33 not 37-57 or 63-83)
only need to compare

input1
a	5-10, 30-40, 45-60, 80-90, 100-120		
y	5-10, 30-40, 45-60, 80-90, 91-120		
	
input2
a	1-4
y      30-33, 37-57, 63-83

ouput
a   1-4       Out of Range
y   30-33   With in Range

hope below perl script can help you some

my %hash=(a=>'1-4', y=>'30-33', b=>'30-42');
my $flag;
while(<DATA>){
	$flag = 0;
	my @ranges = split("[- 	]",$_);
	my $comp = $hash{$ranges[0]};
	my @tmp=split("-", $comp);
	if ($tmp[0]>$ranges[$#ranges] or $tmp[1]<$ranges[1]){
		print $ranges[0]," ",$comp," out of range\n";
	}
	else{
		for(my $i=1;$i<=9;$i+=2){
			if($ranges[$i]<=$tmp[0] and $ranges[$i+1]>=$tmp[1]){
				print $ranges[0]," ",$comp," in range\n";
				$flag = 1;
				last;
			}
		}
		print $ranges[0]," ",$comp," out of range\n" if $flag!=1;
	}
}
__DATA__
a 5-10, 30-40, 45-60, 80-90, 100-120
y	5-10, 30-40, 45-60, 80-90, 91-120
b	5-10, 30-40, 45-60, 80-90, 91-120