in reply to selecting N random lines from a file in one pass

If the focus is efficiency, why are you chomping every line when you only want a few? Moving the chomp inside the if will speed up your code by about 10% - 12% (based on a quick benchmark run I did).

-xdg

Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.