A Perl program that prints itself

I wrote this program long ago, and now have no idea how it works.

$s='for($i=0;$i<2;$i++){print q/$s=/x!$i.chr(39)x!$i.$s.chr(39)x!$i.";"x!$i;}';
for($i=0;$i<2;$i++){print q/$s=/x!$i.chr(39)x!$i.$s.chr(39)x!$i.";"x!$i;} 

Some guy wrote a simpler one here.