use replace if possible, fallback to perl