use filter; @m_h= filter { s/tw/tr/g } grep /^t/i, @foo; # or, if you don't like prototypes: @m_h= filter( sub { s/tw/tr/g }, grep /^t/i, @foo );