#!/usr/bin/perl while (<>) { print if m!(^-{0,1}\d*)\s+(\d*)!m; print "$_\n" for ($1 .. $2); } But when I allow both to be negative it doesn't: #!/usr/bin/perl while (<>) { print if m!(^-{0,1}\d*)\s+(^-{0,1}\d*)!m; print "$_\n" for ($1 .. $2); }