For the square, we have that each side's length is 2p, since the perimeter is the sum of the length of all sides of a geometric figure, this means that we have to add all the lengths of the square like this:
[tex]\begin{gathered} P=2p+2p+2p+2p_{} \\ \Rightarrow P=8p \end{gathered}[/tex]And we can do the same with the 3 sides of the triangle:
[tex]\begin{gathered} P=2x+2x+3x+1 \\ \Rightarrow P=7x+1 \end{gathered}[/tex]