Not related to your question, but when you use
$filename_pattern = "Remedy.csv" and then
/$filename_pattern/, that period character is used as the regex special character (like using
[^\n]), which may match more than you intend (eg, it matches "Remedy_csv"). If you want to match strings in which that string occurs literally, quote it (like
/\Q$filename_pattern\E/ or with
quotemeta). However, I suspect you really want equality:
$_ eq $filename_pattern;, or maybe case-insensitive equality (eg, for Windows):
lc $_ eq lc $filename_pattern.