in reply to replace string

What if you have <> inside your tags? Text::Delimited can solve a lot of your problems for this kind of parsing. More info here.

#! usr/bin/perl use strict; use warnings; use Text::Balanced qw/extract_bracketed/; while( <DATA> ) { my $in = $_; print "\nIN : $in"; ## input my $out = $in; ## OK if you never have \<\> inside \<\> $out =~ s/\<([^\>]+)\>/\n\{$1\}\n/g; print "\tOUT 1 : $out"; ## simple output ## Have to be more clever if it does ## extract balanced delimiters my @extracted = extract_bracketed($in, '<>'); if (!defined$extracted[0]){ ## undefined if no balanced delimiters existed ## so print straight out print "\tOUT 2 : $in"; } else { ## balanced delimters were found, ## so process them as before print "\tOUT 2 : "; for (@extracted){ s/^\<(.+)\>$/\n\{$1\}\n/g; print $_; } } } __DATA__ [SOUR] Por Gisela Orozco 312.527.8461/ Chicago\ <line> Por Gisela Orozco< ttl>312.527.8461/ Chicago</ttl> <<test>>extra bumphf

Will produce the right output more robustly (see the last input line) :

IN : [SOUR] OUT 1 : [SOUR] OUT 2 : [SOUR] IN : Por Gisela Orozco 312.527.8461/ Chicago\ OUT 1 : Por Gisela Orozco 312.527.8461/ Chicago\ OUT 2 : Por Gisela Orozco 312.527.8461/ Chicago\ IN : <line> Por Gisela Orozco< ttl>312.527.8461/ Chicago</ttl> OUT 1 : {line} Por Gisela Orozco { ttl} 312.527.8461/ Chicago {/ttl} OUT 2 : {line} Por Gisela Orozco< ttl>312.527.8461/ Chicago</ttl> IN : <<test>>extra bumphf OUT 1 : {<test} >extra bumphf OUT 2 : {<test>} extra bumphf

HTH

Just a something something...