Calculate perimeter