#!/usr/bin/perl -w use strict; my $str = 'abcadefaghi'; my $pat = '(a.)'; my $repl = '$1 '; #$str =~ s/$pat/$1 /g; # Working non-dynamic demo $str =~ s/$pat/$repl/g; print "$str\n"; # prints: '$1 c$1 ef$1 hi'