my $command = "tar --tape-length $TAPE_LENGTH -cf $destination $source"; my ( $input, $output ); open3( $input, $output, '', $command ); while ( my $line = <$output> ) { print "from tar: '$line'\n"; if ( $line =~ m/Prepare volume/ ) { # need to change tapes ... } }