use strict; use warnings; open (my $fhConditions, "<1.txt"); my $l=6; open (my $read, "<2.txt"); my @e = <$read>; my $d = join('', @e ); $d =~ s/\s+//g; while (my $line = <$fhConditions>) { chomp $line; my @pos = $line[$i] =~/chr*\s+(.+?)\s/g; if($pos[0] =/[0-9]/) { my $match = substr($d,$pos[0],$l) print "$line" if $match =~m/AAGCTT/; } if($pos[1] =/[0-9]/) { my $a = $pos[0]-$l; my $match = substr($d,$a,$l); print "$line" if $match =~m/AAGCTT/; } }