# example: building a binary tree from an unsorted file of strings $_ = <>; chop; my $llref; { $llref = { data => $_ }; } while ( <> ) { chop; Bin( $llref ); } # on completion there is only $llref defined pointing at a dynamic list element being an anonymous hash with links to other similar list elements. sub Bin { my $llref = shift; if ( $_ < $llref -> { data } ) { if ( defined ( $llref -> { left } ) ) { Bin( $llref -> { left )); } else { $llref -> { left } = { data => $_ }; } elsif( $_ > $llref -> { data } ) { if ( defined( $llref -> { right } ) ) { Bin( $llref -> { right )); } else { $llref -> { right } = { data => $_ }; } } }