#either this my @no_punct = $line =~ /(\w+)/g; #or this my @no_punct = grep{$_}split /\W|\s/, $line;