my (@match, @notmatch); for (@rawentries) { if (/Endbit/i) { push @match, $_; } else { push @notmatch, $_; } } my @newlist = (@notmatch, @match); # the ones that match float to the bottom