#!/usr/bin/perl -w use strict; my $txt = "foo *text* bar *bat* bounce"; $txt =~ s/\*(.*?)\*/$1<\/em>/g; print $txt."\n"; #### s/ substitute \* a star (.*?) then a group of arbitrary characters (but only match once, see below) \* then another star / replace it with $1<\/em> what we just got, surrounded by 's /g; do this across the entire string; #### foo text* bar *bat bounce - instead of - foo text bar bat bounce