in reply to Is Group Substitution Possible?

In your example you don't have a clear order in which the pattern can happen so the second part of the code will be useful. If the order is set then you can use the first part of the code

#!/usr/bin/perl -w $string = "Test: FileNames can't have / \\ and other special character +s"; $string =~ s/(.*):(.*)\/(.*)\\(.*)/$1COLON$2FSLASH$3BSLASH$4/; # Note +greedy substituion in place print $string,$/; my %subs = qw(: COLON / FSLASH \\\\ BSLASH); $string =~ s/$_/$subs{$_}/ for (keys %subs); print $string,$/;
Output

TestCOLON FileNames can't have FSLASH BSLASH and other special charact +ers TestCOLON FileNames can't have FSLASH BSLASH and other special charact +ers

Replies are listed 'Best First'.
Re^2: Is Group Substitution Possible?
by ketema (Scribe) on Jul 28, 2005 at 20:11 UTC
    The order could possibly vary.