@match = $data =~ m|([^<]*)|sg; foreach my $m (@match) { my $prepared_string = prepare_string($m); $data =~ s/$m/$prepared_string/s; }