#!/usr/bin/perl use strict; use warnings; my $outputfile = "/Users/edwardtickle/Documents/CC22CDS.txt"; open FILE1, "/Users/edwardtickle/Documents/CC22positions.txt" or die "cannot open > CC22: $!"; open FILE2, "/Users/edwardtickle/Documents/CDSpositions.txt" or die "cannot open > CDS: $!"; open (OUTPUTFILE, ">$outputfile") or die "Could not open output file: $! \n"; while () { if (/^(\d+)/) { my $CC22 = $1; while () { if (/^(\d+)\s+(\d+)\s+(\S+)/) { my $CDS1 = $1; my $CDS2 = $2; my $CDS3 = $3; if ($CC22 > $CDS1 && $CC22 < $CDS2) { print OUTPUTFILE "$CC22 $CDS1 $CDS2 $CDS3\n"; } } } } } close(FILE1); close(FILE2);