in reply to Scope of $/

Its a global variable, so use local and set the variable to what you need it to be, as in
sub firstline { use autodie qw/ open /; local $/ = "\n"; open my($fh),'<',$_[0]; return scalar <$fh>; }