my $offset = tell STDIN; while ( my $line = ) { print "[$offset] $line"; } continue { $offset = tell STDIN; } #### [0] 12345 [6] 1234567890 [17] a [19] b [21] c #### my $tlc = substr $line, 0, 3; push @{ $offsets_for{$tlc} }, $offset;