#! /usr/bin/perl -w use strict; use locale; my $string = "_'nada_komo_el_'sol_"; $string =~ s/(_)([^']+?)(_)/$1'$2$3/go; print $string;