use strict; use warnings; while (my $line = ) { (my @words) = $line =~ /([^:.,\s]+)/g; # (my @words) = split /[:.,\s]+/, $line; #TRY THIS LINE INSTEAD next unless @words; # skip input lines that have no "words" print "\'$_\' " foreach @words; print "\n"; } =prints: Note: that the first data line with only ':' is skipped. 'this' 'is' 'a' 'simple' 'space' 'separated' 'line' 'this' 'is' 'a' 'line' 'with' 'spaces' 'at' 'the' 'beginning' 'this' 'line' 'has' 'multiple' 'spaces' 'embedded' 'in' 'it' 'a' 'comma' 'list' 'a' 'b' 'unconsidered' 'are' '(1)' 'item' 'lists' 'or' '(comments' 'like' 'this)' '$this_is_a_program_variable' 'this' 'shows' '"a' 'quote"' =cut __DATA__ : this is a simple space separated line this is a line with spaces at the beginning this line has multiple spaces embedded in it a comma: list,a,b unconsidered are: (1) item lists or (comments like this) $this_is_a_program_variable this shows "a quote"