my $fmt= "LIJ"; while( 1 ) { last if length( pack substr($fmt,0,1), 0 ) == length( pack "p", "" ); $fmt= substr( $fmt, 1 ); die "No unpack format for integers the same size as pointers" if ! $fmt; } $fmt= substr( $fmt, 0, 1 ); my $addr= unpack $fmt, pack "p", $string;