$output = `program args`; # collect output into one multiline string @output = `program args`; # collect output into array, one line per element #### #!/usr/bin/perl # use strict; use warnings; my @output = `bpdbjobs`; for my $line (@output) { chomp $line; my @matches = $line =~ /(\d+)?\s+((\b[^\d\W]+\b)|(\b[^\d\W]+\b\s+\b[^\d\W]+\b))?\s+((Done)|(Active)|( \w+\w+\-\w\-+))?\s+(\d+)?\s+((\w+)|(\w+\_\w+)|(\w+\_\w+\_\w+))?\s+((b[^\d\W]+\ b\-\b[^\d\W]+\b)|(\-)|(\b[^\d\W]+\b))?\s+((\w+\.\w+\.\w+)|(\w+))?\s+((\w+\.\w+ \.\w+)|(\w+))?\s+(\d+)?/g; ## <<--- Beware of the global modifier g here! if (@matches) { # @matches now is an array containing the captured matches # Pretty printing time ? } }