On Mon, Nov 9, 2009 at 10:56 AM, Jim Gibson <jimsgib...@gmail.com> wrote:
> However, here is a shortened form using regular expression: > > my @output = $line =~ m{ \G (..) .. }gx; > > Verify how either of these works when you do not have a multiple of 2 > characters in your input. > > It has other problems too: use strict; use warnings; use 5.010; my $str = "ab--cd--ef"; my @pieces = $str =~ /\G(..)../g; say "@pieces"; The output is: ab cd Note that the last two characters 'ef' were not included in the result. You need a multiple of 4 characters in the string for that regex to work correctly.