my %AVSo_by_sig; sub cid_date { @cid_and_date = split /::/, $_[0], 2; return "@cid_and_date"; } sub avs { return (split /::/, $_[0], 3)[2]; } # create a hash of cid_date->elem for the old elements for (@AVSo) { $AVSo_by_sig{cid_date($_)} = $_; } # compare new elements to old via their cid_dates for my $new (@AVSn) { my $old = $AVSo_by_sig{cid_date($new)}; if ($old && avs($old) ne avs($new)) { # changed from old to new print $new; } }