Howdy. You're almost there, it's just the way you're using the file that's giving you trouble. You should open the file once for reading, slurp in the @file array, close the file, and then open it again for appending (if necessary) to write the $tempName var. I'd think you'd want something like this:
$tempName= $query->param('searchText'); #user supplied
open (FILE, "filename");
@file = <FILE>;
close FILE;
$temp = join('',@file);
$temp =~ /$tempName/s;
if ($temp eq '')
{
open FILE, ">>filename";
print FILE $tempName . "\n";
}
close (FILE);