in reply to comparing strings

I'll assume your arrays contain a single character per element, though that's unclear from your description.
while(@lines1 > 0 and @lines2 > 0) { last if shift(@lines1) ne shift(@lines2); } print "*\n" if @lines1 > 0 or @lines2 > 0;

Makeshifts last the longest.