To calculate the perimeter of a rectangular rug when it is given that the perimeter is 40 feet, you can use the formula p=2l+2w, where p represents the perimeter, l represents the length, and w represents the width. By substituting the given perimeter value into the formula, you can solve for the length and width of the rug.