#!/usr/bin/perl -w use Data::Dumper; my %alllines; # hash: line => (arbitrary value) my @enabled_lines; # array: flat list while () { chomp; # not testing with defined as '0' couldn't be a valid url. my ($data) = /([^\s#]+)/; # this $alllines{$data} = 1 if $data; # works my ($enabled) = /([^\s#]+)#/; # this push @enabled_lines, $enabled if $enabled; # doesn't work } print Dumper(\%alllines); print Dumper(\@enabled_lines); __DATA__ astandardline #acommentedoutline # alinewithspacesbeforeandafterthecommentcharacter therealdata # a subordinate comment, this contains whitespace as it should be ignored linewherethetabsshouldbeignored alinewith # multiple # comment # characters