$list = '1,2,3,4,5,6,7,8'; @odds = grep $_ % 2, split(/,/, $list); @evens = grep not($_ % 2), split(/,/, $list);