my @data = map [ split ], grep /\S/, <>; ### <> reads from stdin (or a file named on the command line) You would need instead.