http://www.perlmonks.org?node_id=1004807


in reply to rotate a vector with a regex?

Are you interested in the end product or do you want all intermediates?

This will give you the end product:

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my $string = "12345"; $string = substr( $string, 1 ) . substr( $string, 0, 1 ); say $string; __END__ 23451

EDIT: Just realized you were asking for something else. Oops. I think AnomalousMonk is correct about it not being possible this way. Regarding the errors, you need to specify the second capture group since the second set of parentheses you have are part of the lookahead. This gets rid of the warnings:

$ perl -WE '$string = "12345"; $string =~ s/(.)(?=(.))/$2$1/g; say $st +ring' 213243545