#!/usr/bin/env perl use strict; use warnings; my $sep = ',-->'; my $sep_len = length $sep; my $tail = ",\n"; my $last; while () { my ($first, undef, $second) = unpack "A3 A$sep_len A3"; print $last, $sep, $second, $tail if defined $last; $last = $first; } __DATA__ 123,-->456, 456,-->234, 234,-->789, 789,-->123, #### 123,-->234, 456,-->789, 234,-->123,