use strict; use warnings; use feature 'say'; use POSIX ":sys_wait_h"; use Capture::Tiny ':all'; my $cmd = 'cmd /c copy a1GBfile a1GBfile_copy /z'; my $out = IO::File-> new_tmpfile; capture_stdout { my $pid = system( 1, $cmd ); while () { last if waitpid( $pid, WNOHANG ); undef local $/; seek $out, 0, 0; my $s = <$out>; next unless $s and $s =~ m/.*\D(\d+)%/s; say STDERR "progress so far: $1 percent"; sleep 1; } } stdout => $out; close $out; __END__ progress so far: 0 percent progress so far: 60 percent progress so far: 70 percent progress so far: 80 percent progress so far: 89 percent progress so far: 99 percent