#!/usr/bin/perl -w $string = "Test: FileNames can't have / \\ and other special characters"; %s = (":" => "COLON", "/" => "FSLASH", "\\" => "BSLASH"); $t = (join "|", map quotemeta($_), (keys %s)); $string =~ s/($t)/$s{$1}/g; print "$string\n";