You can use open to connect to a command with a pipe and get its output. Commandline progress bars work by printing the carriage return character ("\r"), to set the cursor back to the start of line and overwriting the text. To capture each update in progress, you can set the input record separator to "\r".
use feature qw(say);
my $rsync_command = 'rsync ... --progress';
open my $RSYNC, '-|', $rsync_command or die "Failed to start rsync: $!
+";
local $/ = "\r";
while (<$RSYNC>) {
if (/\A\s/) { # progress lines start with whitespace
say 'Progress: ', $_;
}
else {
print 'File: ', $_; # file lines have newlines at the end
}
}
close $RSYNC;
The code to differentiate between a filename and a progress line could be upgraded a bit but this is the general approach I would use to monitor progress bars.