Use open or backticks instead of system . System doesn't capture the output of the command.
Open :
open ($filehandle ,"/usr/bin/which prg|") or die "Error $!\n";
while(<$filehandle>)
{
...
}
Backticks :
my $output = `/usr/bin/which prg`;
chomp $output;