in reply to sorting type question- space problems

Your "virtual" file could be a directory tree structure. Assuming the keys are valid names for directories, you could do something like this:

use strict; use warnings; my $dir = "data.tmp"; mkdir $dir unless -d $dir; while(<DATA>){ my( $key1, $key2, $data ) = split /\s+/, $_, 3; mkdir "$dir/$key1" unless -d "$dir/$key1"; mkdir "$dir/$key1/$key2" unless -d "$dir/$key1/$key2"; open my $fh, ">>", "$dir/$key1/$key2/data.txt"; print $fh $data; close $fh; } opendir( my $dh, $dir ); for my $key1 (sort grep { !/^\./ } readdir $dh) { opendir( my $dh1, "$dir/$key1" ); for my $key2 (sort grep { !/^\./ } readdir $dh1) { open my $fh, "<", "$dir/$key1/$key2/data.txt"; while( <$fh> ) { print "$key1\t$key2\t$_"; } close $fh; } } system( "rm -rf $dir" ); __DATA__ key1 key2 ndnjfgdsjfjjkjjfjf... key1 key2 kdfkjdfgdfugbjndkfgkjgndkjfjkd key43 key21 sdkjfhdghdbgbd key1 key3 jujdejnsduhffnjj key2 key2 jhzezhdjjf...

If things go wrong, you only have to delete the one directory... WARNING: No error checking in this code, you need to add that yourself!