use ntheory qw/fromdigits todigitstring/;

print "0  0  0\n";  
for (0..2e5) {
  
  my $pal = todigitstring($_, 3);
  my $b3 = $pal . "1" . reverse($pal);
  
  my $b2 = todigitstring(fromdigits($b3, 3), 2);
  
  print fromdigits($b2,2),"  $b3  $b2\n"   if $b2 eq reverse($b2);
}