#!/usr/bin/perl use strict; use warnings; my @strings; while () { # Split up input stream using dashes my @smallarray = split '-'; # @smallarray now has 'aaa bbb ccc', etc. # Iterate through @smallarray items and split them up using spaces # Create an array of anonymous array references # The references are the array resulting from split, using [] push(@strings, [split /\s/]) foreach (@smallarray); }