foreach (@nums){ push (@even, $_) if /\/2/; #match all numbers that are even push (@odd, $_) if /^\/2/; #match all odd numbers }