You need to
properly quote variables with spaces or other special characters in them.
If you want to use Perl, it's rather weird to not do the actual matching in Perl also. Running the grep twice just because you want the number of matches first is also ... intriguing. Here, I cannot resist.
Code:
#!/usr/bin/perl
print "Enter a File name :";
chomp ($file = <STDIN>);
print "\n Searching file :";
if (-e $file)
{
print "File Found\n";
$lines = `wc -l < $file`;
chomp $lines;
print "Total number of lines in the file = $lines \n";
print "Enter the pattern to search :";
chomp ($pattern = <STDIN>);
print "\n";
# to search the no of words (pattern search)
$abc=`grep "$pattern" $file`;
$count = () = $abc =~ m/\n/g;
print "Total number of results found: $count\n";
print "here are the results ...\n$abc\n";
}
else{
print "File not Found\n";
}