`your_command | tee test.txt` =~ /your_capturing_regex/ #### $ perl -le '`date | tee test.txt` =~ /^(\w+)/; print $1' Tue #### $ cat test.txt Tue 18 Mar 2014 11:02:34 EST #### system "echo @{[`your_command` =~ /your_capturing_regex/]} > test.txt" #### $ perl -e 'system "echo @{[`date` =~ /^(\w+)/]} > test.txt"' #### $ cat test.txt Tue