use strict; use warnings; use File::Slurp qw(read_file); use Data::Dump qw(dump); my $ipairs = shift; my $dbf = shift; my $ofile = $dbf.'.cool'; print "reading database ... \n"; my %idb = reverse map {/^(.*(rs\d{1,20}\s+rs\d{1,20}).*)$/} grep {/^.*rs\d{1,20}\s+rs\d{1,20}.*$/} read_file $dbf or die "$!"; print "reading pairs ... \n"; my @pdb = read_file $ipairs or die "$!"; print "removing endlines ... \n"; map {chomp()} @pdb; print "writing output file\n"; my $head = "CHR1 CHR2 SNP1 SNP2 OR_INT STAT P"; open ODF, ">$ofile" or die "Can't redirect stdout"; print ODF "$head\n"; foreach my $rsp (@pdb){ if($idb{$rsp}){ print ODF "$idb{$rsp}\n"; } } close ODF;