I have 2 file
1. amayaM
2. vismayaM
3. vismayaN
1. amayamAn
2. vismayamAn
3. vismayamer

I need to check each character by character between 2 files and if the nonmatching character in first file is M then print the word in first file else no output.

1. amayaM
2. vismayaM

Recommended Answers

All 3 Replies

Hi laksraju,

Please could you show what you have done so far. The area of the code where you are having problems. Writing the code for you would not help you in the long run.

Secondly,you might look into the archieve of this forum. This kind of problem has been solved again and again. You can adapt one of the solved problems for your usage. And if you are still having problems, then come back we will be able to help.


the code was done like this

use warnings;
use strict;

open my $fh1, '<', 'first_file.txt'  or die $!;
open my $fh2, '<', 'second_file.txt' or die $!;

while ( my $s1 = <$fh1> ) {
    chomp $s1;
    chomp( my $s2 = <$fh2> );

    ( $s1 ^ $s2 ) =~ /[^\x00]/;
    substr( $s2, $-[0], 0 ) ='M' if defined $-[0];
    print $s2, "\n";


close $fh2;
close $fh1;

Hi laksraju,

You apprently, didn't understand the solution to a similar question, you posted on Perlmonks and the solution given to you by Kenosis.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.