#! perl -slw use strict; while( ) { chomp; s[^(\QThe seller has the following *fruit*\E types:)(.+)$]{ my($const, $rep ) = ( $1, $2 ); $rep =~ tr[* ().][#]d; $rep =~ s[,\s*and][and]; "$const*($rep)*." }e; print; } __DATA__ The seller has the following *fruit* types: ( *apples* , *oranges* , *pears* , *berries* , and *mangoes* ). The seller has the following *fruit* types: *apples* , *oranges* , *pears* , *berries* , and *mangoes* . The seller has the following *fruit* types: ( *apples* , *oranges* , *pears* , *berries* and *mangoes* ). The seller has the following *fruit* types: *apples* , *oranges* , *pears* , *berries* and *mangoes* .