grep (/$filename/i, $key) foreach my $key (keys %path_versions)
FYI, this form of statement modifier is syntactically incorrect (in addition to doing nothing with the output of grep if the statement was modified so it could compile). See Statement Modifiers in perlsyn.
Specifically, a for loop statement modifier cannot use a named loop variable, but instead uses the implicitly localized (or 'topicalized') default scalar $_. E.g.:
>perl -wMstrict -le
"my @words = qw(foo bar baz);
print qq{'$_'} foreach @words;
"
'foo'
'bar'
'baz'