open IN, "d1.txt" or die "No such file:$!\n"; open OUT, ">ABC.txt" or die; while ( ) { chomp $_; $a[ $l ] = $_; ++$l; } my @array = qw( doxorubicin is a potent anti-estrogen drug and tamoxifen ); for ( $i = 0; $i < $l; ++$i ) { for $z ( @array ) { if ( $z =~ /\b\w^$a[$i]$\b/i ) { $z =~ s/$z/$z<\/span>/; $i++; print "@array "; } } }