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;