foreach my $thing(@b){ if(scalar grep(/^$thing/,@a) == 0){ push(@c,$thing); } }