in reply to Find line number and offset inside line given a byte offset in string

You can get the byte offset past each newline into an array like this:

our @ofs = (0); push @ofs, pos while $string =~ /(\n)/g;
Then you can find the line number and line offset of a given byte offset by calling:
sub ofs2line { my $offset = shift; for (0 .. $#ofs) { return ($_, $offset-$ofs[$_-1]) if $offset < $ofs[$_]; } return ();
That takes offsets to start with zero. Untested, beware fencepost errors.

After Compline,
Zaxo