my $str1 = "AATAGCAATTGACAAT"; my $str2 = "CAATCGGAACCAGCAT"; ($concat = "$str1#$str2") =~ s/(.*?)(.*)#\2(.*)/$1$2$3/; print $concat, "\n";