For such kind of activity always follow chomp.
It removes new line from the string, right now without chomp your string 1 = Mahesh\n
chomp will simply make it Mahesh
print "Enter a word: \n";
chomp($string1 = <STDIN>);
$string2 = 'Mahesh';
if($string1 eq $string2){
print "Match \n";
}
else {
print "Does not match \n";
}