in reply to What am I missing?

Your script does not print out a 2 because because it removes all numbers divisible by 2. What it should do is preserve the first one.

The least intrusive change to your program to get it working is this:

foreach $i (@f) { @n = grep {$_ % $i != 0 || $_ == $i } @n; }