As the others have pointed out the shell doesn't work like that. A possible workaround is to alias the output of the program to a command:
#!/usr/bin/perl -w
use strict;
my $dir = '/usr/bin';
if (chdir $dir) {
print $dir;
}
else {
print STDERR "Couldn't cd to $dir\n";
print '.';
}
__END__
Then in your shell set an alias:
alias mycd='cd `perl mycd.pl`'