!/usr/bin/perl use strict; use warnings; my $text; while($text=){ $text =~ s~(.*?)<\/font>~\[color=$2\]$5\[/color\]~ig; print $text . "\n"; } # expected output: # [color=blue]
Some text[/color],
an a __DATA__
Some text
,
an a