#!/usr/bin/perl use strict; use warnings; use Tie::File::Custom; tie *fh, 'Tie::File::Custom', 'num.dat' or die "Unable to tie : $!"; (tied *fh)->NL( "\n\\d+\n" ); # Lines with numbers by themselves are record terminators while ( ) { (tied *fh)->CHOMP( $_ ); print "$_\n"; }