in reply to How is outputting to an array different from outputting to a file

Your code definitely does not compile so it's not clear what you've really tried. Do you intend to have the second for loop inside the foreach loop? Your indentation suggests otherwise. You don't have a closing brace there (among other syntax errors).

The short and long of it: replace this from the first snippet:

system("lpstat -v -d -p -l -D >junk.txt"); open RI,"<junk.txt" || die "Can't open junk.txt for reading:$!\n"; my $data = do { local $/; <RI> }; # or however you load it.
With this:    my $data = `lpstat -v -d -p -l -D`; An array isn't really necessary. In fact, in your example you were putting the entire results of the command into only the first element of your array.

blokhead