#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11107298 use warnings; my $string ="test\nI want length of this line\n test"; my $position = 12; pos($string) = $position; $string =~ /.*\G.*\n?/; my $length_of_line = length $&; print "length of line at $position is $length_of_line\n"; #### length of line at 12 is 27