in reply to Passing regex inside via a variavble

The problem isn't in the regular expression, but what it is matching.

if ( /^$source.*$COB/ ) matches the regular expression against the variable $_: if your file name is stored in some other variable, that condition won't work. If you think your file name is being stored in $_, you'll have to include some code showing how you are setting the value of $_ for us to understand why that isn't working.

Alternatively, if the lines you are reading in get stored in a variable $foo then you could modify the condition to check the regular expression against the variable $foo, like this: if ( $foo =~ /^$source.*$COB/ ).

Best, beth