use List::MoreUtils qw( apply ); print join ", ", apply { chomp; s/(d)/new($1)/ } @a;