in reply to Splitting string based on potentially escaped character

The split/join sequence suggests  s/// substitution:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $string = 'foo+bar+baz+boff'; my $separator = '+'; my $replace = '<REPLACE>'; ;; $string =~ s{ \Q$separator\E }{$replace}xmsg; dd $string; " "foo<REPLACE>bar<REPLACE>baz<REPLACE>boff"
Note that this works regardless of the meta-nature of the separator character/string:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $string = 'fooXbarXbazXboff'; my $separator = 'X'; my $replace = '<REPLACE>'; ;; $string =~ s{ \Q$separator\E }{$replace}xmsg; dd $string; " "foo<REPLACE>bar<REPLACE>baz<REPLACE>boff"

Update: See quotemeta; see perlre, perlretut, and perlrequick; see Regexp Quote-Like Operators in perlop for s///.


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Splitting string based on potentially escaped character
by Anonymous Monk on Mar 07, 2017 at 19:10 UTC
    It is unnecessary and extremely annoying for you to provide your path and to wrap the code the way you do, consider: Invocation:
    perl -wMstrict -MData::Dump -le
    
    Code:
    my $string = 'fooXbarXbazXboff'; my $separator = 'X'; my $replace = '<REPLACE>'; $string =~ s{ \Q$separator\E }{$replace}xmsg; dd $string;
    Yields
    foo<REPLACE>bar<REPLACE>baz<REPLACE>boff
    
    So much more useful for the OP and no additional effort on your behalf.