#!/usr/bin/perl -w use strict; my @red_things = qw(apple little_corvette strawberry lava); my @fruits = qw(apple pineapple strawberry banana); my @sorted_red_things = sort @red_things; my @sorted_fruits = sort @fruits; while (@sorted_red_things || @sorted_fruits) { my($thing,$fruit)=($sorted_red_things[0],$sorted_fruits[0]); if (defined($thing) and (!defined($fruit) or ($thing lt $fruit))) { print "A red thing that's not a fruit: $thing\n"; shift @sorted_red_things; } elsif (!defined($thing) or ($thing gt $fruit)) { print "A fruit that's not red: $fruit\n"; shift @sorted_fruits; } elsif ($thing eq $fruit) { # It's in both lists shift @sorted_red_things; shift @sorted_fruits; } }