{ my %translate =( '\n'=>"\n", '\r'=>"\r", '\t'=>"\t" ); my $regex=join "|", map { quotemeta $_ } keys %translate; sub myqw { local $_ = shift; s/\#.+//g; # bye bye comments return map { if ($_ eq '\undef') { undef; # undef element in the array } else { s/($regex)/$translate{$1}/ge; # safer than eval $_; } } split " "; } } # test it print join "|", myqw (q[ this is a set of words # and they are commented as well a b b\t\te # b tab tab e c # d # remove d because we wont need it e\ne # e newline e g \undef h ]); __END__ this|is|a|set|of|words|a|b|b e|c|e e|g||h