use strict; use warnings; # trivial variation on tybalt89's to retain # both odd and even one after the other my $sample = "041424344454647484940414"; my @allin = $sample =~ /(\d)(\d)/g; # more ordered output using subs in regex my @odds_vs_evens = (); $sample =~ s/(\d)(\d)/push(@odds_vs_evens,[$1,$2])/eg; print $_->[0].'->'.$_->[1]."\n" for @odds_vs_evens;