use strict; use warnings; use Data::Dumper; ; my @products = keys %{{ map { /^\d+\s+(\w+)$/ ? ($1,1) : () } }}; print Dumper(\@products); __DATA__ price product 200 shoe 20 shirt 10 shirt 5 hat #### $VAR1 = [ 'hat', 'shirt', 'shoe' ];