my %hash $hash{$.} = $_ while <>; #### my @lines = <>; #### my @matched_idxs = grep {$lines[$_] =~ /$re/} 0 .. $#lines;