in reply to pattern matching

That should be

$str="himanshu.txt^@"; if($str =~ /(\w+)\.(\w+)/) { $str = "$1.$2"; }

What is your "^@" ? That looks like an ASCII 0, as less(1) would show it. You can sense that and remove it with

if ($str =~ s/\0$//) { print "found NUL byte at the end of '$str'\n"; }