foreach $elem(@data){ ($sub,$max)=split/\|/,$elem; @found=grep /^$sub:/,@ref; foreach $f(@found){ ($id,$time)=split/\|/,$f; if($time ne $max){ push @set,$id; } } }