use feature 'say'; $test = 'abc1234asf'; $test =~ /(?\w{4})(?\w{4})/; #say 'one:', $+{one}; #works #say 'two:', $+{two}; $test =~ s/(?\w{4})(?\w{4})/$+{four}$+{three}/; say 'one:', $+{one}; #NOT works say 'two:', $+{two}; say; say 'three:', $+{three}; say 'four:', $+{four}; say; say 'output:', $test; OUTPUT: ------- one: two: three:abc1 four:234a output:234aabc1sf