#!/usr/bin/perl -w use strict; use Data::Dumper; my %alllines; # hash: line => (arbitrary value) my @enabled_lines; # array: flat list while () { next if /^\s*#/; # may as well skip commented out lines 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) = /([^#]+)#/; # this push @enabled_lines, trim($enabled) if $enabled; # doesn't work } print Dumper(\%alllines); print Dumper(\@enabled_lines); sub trim { $_ = shift; s/^\s+//; s/\s+$//; return $_; } __DATA__ astandardline #acommentedoutline # alinewithspacesbeforeandafterthecommentcharacter therealdata # a subordinate comment, this contains whitespace as it should be ignored linewherethetabsshouldbeignored alinewith # multiple # comment # characters