Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Shift regex search back 4 characters...

by ablanke (Prior)
on Mar 08, 2017 at 10:54 UTC ( [id://1183936] : note . print w/replies, xml ) Need Help??


in reply to Shift regex search back 4 characters...

Hi,
maybe i'm simplifying your requirements too much or it's a matter of performance, but you could solve this by splitting the numbers.
#!/usr/bin/perl use strict; use warnings; my $numbers = '222,345,222,678,222,222,543,111,222'; my @numbers = split(',', $numbers); my $i = 1; for my $number (@numbers) { if ( '222' eq $number && $i < scalar(@numbers) ) { print "AFTER $number-$numbers[$i]\n"; } $i++; }