open(my $fh, '-|', "diff -r $some_dir/$f $other_dir/$f") or die "diff: $!"; my $diff = <$fh>; close $fh; if($diff) { # there were diffs }