my @images = ( [], [] ); my ( $img_1_str, $img_2_str) = split( '\|', $str); @{ @images[0] } = $img_1_str =~ m/(\w+\.jpg)/gi; @{ @images[1] } = $img_2_str =~ m/(\w+\.jpg)/gi;