in reply to skipping until an alement is matched

You need to move the my $seen; line out of the loop. You are effectively clearing $seen each time you start the loop. Otherwise your code seems to do what you want.

Vavoom