But you shouldn't. You're neither checking whether your attempt to run wc succeeded nor whether the pattern matched. Under these circumstances, $lines may wrong be assigned whatever was in $1 from a previous match. Don't use $1 blindly. Always guard your matches with an if or assign the captures to a list. See Gilimanjaro's snippet.