sub Check_request_file { my ($file_to_check) = @_; local *_; # Protect caller's $_. open(local *FILE, '<', $file_to_check) or die("Unable to open SPROC file $file_to_check: $!\n"); while () { if (/SPROC\sName\:(?!\s[rR]eception)/) { close(FILE); # So we can delete it unlink($file_to_check) or die("Unable to delete SPROC file $file_to_check: $!\n"); return; # Optional, since will # return false for a closed file. } } }