#!/usr/bin/perl use strict; use warnings; my @AoA = ( ['firstRowCol1 asdf87534', 'firstRowCol2 junk lj6t90'], ['secondRowCol1 mnhibvygt7','secondRowCol2 7d7d5434'] ); my(@kmers); for my $x (@AoA) { for my $y (@$x) { push @kmers, $y =~ /^(\w+)/; #first word of each element print "@kmers\n"; } } __END__ In the above code, print @kmers."\n"; #prints... 1 2 3 4 print @kmers,"\n"; #prints... firstRowCol1 firstRowCol1firstRowCol2 firstRowCol1firstRowCol2secondRowCol1 firstRowCol1firstRowCol2secondRowCol1secondRowCol2 print "@kmers\n"; #prints... firstRowCol1 firstRowCol1 firstRowCol2 firstRowCol1 firstRowCol2 secondRowCol1 firstRowCol1 firstRowCol2 secondRowCol1 secondRowCol2