foreach $i (@a) { $x = 0; foreach $u (@b) { if ($u eq $i) { $x = 1; last; } } unless ($x) { print "$i\n"; } }