#! perl -sw use strict; while( ) { s[^(<([^>]+?)>)(.*)()]{ (my $x = $3) =~ tr[<>][[]]; "$1$x$4"; }e; print; } __DATA__ my data here further text not good as contains in angle brackets another possibility is one in here and content containing a false and a real