#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11135401 use warnings; open my $fh, '<', \<; while( /^(.*)\n(?=(.*))/gm ) { print "$1 -> $2\n"; } } print "\n"; seek $fh, 0, 0; # reset for different example while( <$fh> ) { chomp; my $pos = tell $fh; print"$_ -> ", (<$fh> // "AT LAST LINE\n"); seek $fh, $pos, 0; }