my @temp = (...); my @a = map {/a_(.*)/ ? $1 : ()} @temp; my @b = map {/b_(.*)/ ? $1 : ()} @temp; #### my @a = map {/a_(.*)/; $1} grep /a_/ @temp; my @b = map {/b_(.*)/; $1} grep /b_/ @temp;