I knew that, but the problem was that Perl is buffering the output, as the other guys said. So I was getting what I wanted, but not when I wanted. To put it simple, the first part showed up only when the second part was printed too, and I didn't get the desired effect.
But the $| = 1 trick solves the problem... thanks guys!