The perl binary "knows" because it is built for a particular system. Any bit-fiddling that needs doing internally is automatically handled, by routines that are built based on the system architecture.
Of course, that doesn't mean that any particular application that one might write to fiddle with bits automatically knows. You have to figure out what kind of system you're fiddling bits for to figure out whether it's "big endian" or "little endian"; how you figure that out depends on your application.
HTH
perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>);
+$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth
+er_name\n"'