open my $IN, '<', 'domain.txt' or die $!; while (<$IN>) { my ($id, $from, $to) = split /[;\s]+/; print "$id; $from $to\n"; for my $pos (0 .. length($hash1{$id})) { print join ' ', $pos, substr($hash1{$id}, $pos, 1), substr($hash2{$id}, $pos * 3, 3), $from <= $pos && $pos <= $to ? 'YES' : 'NOT', "\n"; } }