use strict; my @list = (1,2,3,4,5); foreach (@list) { if ($_ == 2 || $_ == 4) { unshift (@list); next; } print "$_\n"; }