# match lines containing the single word "foo", # ignoring whitespace my @line_numers = grep { $lines[$_] =~ /^\s*foo\s*$/ } 0 .. $#lines;