use strict; use warnings; my $in = '123,-->456, 456,-->234, 234,-->789, 789,-->123, '; print "$1,-->$2\n" while $in =~ / (\d{3}) ,--> \d{3}, \s+ (?= \d{3} ,--> (\d{3}) ) /gsx; # | lookahead assertion | #### 16:28 >perl 1814_SoPW.pl 123,-->234 456,-->789 234,-->123 16:28 >