file1=cnv file start stop size(in bp) 5389769 98256008 3567 7452344 871875466 64547 #### file2=genelist1 name start stop BRCA1 41196312 41277500 TP53 7571720 7590863 #### file3=genelist3 name start stop OMG 29621668 29624380 NR3C1 142657496..142815077 #### !/usr/bin/perl #Open the cnv file with start, stop my $input_gene_file = "path to file"; die "Cannot open $input_gene_file\n" unless (open(IN, $input_gene_file)); my %size_CNV_start_CNV_stop; while (chomp($line = )) { my (@columns) = split /\s+/, $line; my $size = $columns[3]; my $CNV_start = $columns[1]; my $CNV_stop = $columns[2]; $size_and_CNV_start{$size} = $CNV_start; $size_and_CNV_stop{$size} = $CNV_stop; } close(IN); #Now open files for genelist1 and genelist2 with respective start and stops open (MYFILE, "/Users/pathtofile"); @file1 = ; close MYFILE; open (MYFILE2, "/Users/pathtofile"); @file2 = ; close MYFILE2; #Open output file and write the locations/position of each symbol die "output.txt" unless(open( OUT,"> output.txt")); while(defined(my $line1 = <$file1>) and defined(my $line2 = <$file2>)){ sub overlap { my ($CNV_start, $CNV_stop, $Gene_start, $Gene_stop) = @_; if ($Gene_stop < $CNV_start || $Gene_start < $CNV_stop) { return 0; if (Gene_stop > $CNV_start || $Gene_stop > $CNV_stop){ } return 1; } while (defined($symbol = )) { chomp($symbol); { my $CNV_start = $size_and_CNV_start{$size}; my $CNV_stop = $size_and_CNV_stop{$size}; print OUT " $name\ $size\ $CNV_start\ $CNV_stop \n"; } } } close(OUT); #### gene name size start stop xyz 5464 83654272 6735353 ... ...