my $lc = List::Compare->new(@lists); my @common = $lc->get_intersection(); my @common_orig_order; for my $elem (@{$lists[1]}) { push(@common_orig_order, $elem) if (grep (($_ eq $elem), @common)); }