in reply to merging dna sequences

use strict; use warnings; my $a = 'AYGTACTAGACTACAGACTACAGACATCTACAGACTCATCAGCAGCATATTTA'; my $b = 'ACGTACTAGACTACAGACTACAGACATCTACAGACTCATCAGCAGCATATTKA'; my $merged = $a; while ($b =~ /([RYSWKMBDHV])/g) { my $pos = $-[0]; substr $merged, $pos, 1, $1; } # $merge contains what you want

The only "unusual" thing in there is the usage of @- to get the match position.