#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $file1 = <) { next if $line =~ /^\s*$/; #skip blank lines (a common infile goof) my ($key, $value) = split /\s+/, $line; # use better "names" I have # no idea of what a chr col means $file1_hash{"$key:$value"} = 1; } close $infile1; # file handle closure is optional, but I'd do it. ### process each line in file2: ### If a line "matches" with any line in file1, then "E", else "M" ### I don't know that these numbers mean, come up with better comment. while (my $line = <$infile2>) { chomp $line; #so that output with E or M can be on same line next if $line =~ /^\s*$/; #skip blank lines (a common infile goof) my ($chr, $val1, $val2) = split /\s+/,$line; if ( exists $file1_hash{"$chr:$val1"} or exists $file1_hash{"$chr:$val2"} ) { print "$line\tE\n"; # match exists with file 1 } else { print "$line\tM\n"; # match does NOT exist with file 1 } } __END__ Prints the following: chr1 66953622 66953654 E chr1 67200451 67200472 M chr1 67200475 67200478 M chr1 67058869 67058880 E chr1 67058881 67058885 M chr1 67058887 67058895 M