use strict; use warnings; my $test = "this is not OK < but this is ok "; print rep($test); sub rep { $_[0] or return $_[0]; $_[0] =~ s/<(?!url)|(?//g; return $_[0]; }