my @array = (A0-7:123:C, B8-15:456:D); my $check = A4:123:C; foreach my $line(@array){ my $subline = join(":", (split(":", $line))[1,2]); #not sure is that join/split thing works just consider this whatever it takes to get the 123:C into $subline my $subcheck = #again whatever it takes to get 123:C if ($subcheck =~ /$subline/){ $match = &checkRange($check, $line); } } #### my @array = (A0-7:123:C, B8-15:456:D); my $check = A4:123:C; my $test = join(' ', @array); my $find = join(':', ((split(':',$check))[1,2])); my @found = ($test =~ m/\b\w\d+\-\d+:$find\b/g);