Each land cell starts with edges. For every neighbor that is also land, subtract edge (because that side is shared and not part of the perimeter).
Scan the grid cell by cell. For each land cell, count how many of its neighbors are also land. That cell contributes minus its land-neighbor count to the perimeter.
You don't need BFS or DFS. A straightforward double loop with neighbor checks does the job.