# Read a text file, stripping leading and trailing whitespace # and ignoring any lines starting with '#' my $file = shift; open(my $in, '<', $file) or die "error: open $file: $!"; my @lines = grep { s/^\s+//; s/#.*//; s/\s+$//; $_ } <$in>; close($in); for my $x (@lines) { print "x='$x'\n" }